You are on page 1of 2

## Index

1. Comments
2. escape character
3. Variables and Datatypes
4. Typecasting
5. String Slicing and String methods or functions

## Comments :

1. (#) Hash --> Single Line Comment


2. """ snip """ --> Multi line comment

## Escape character :

1. \ --> Escape characters


2. \t --> Tab space
3. \n --> new line character

## Variables, Datatypes :

1. variables are used to store data or to hold values


2. print(type(variable_name)) --> shows varibale type string, intiger or float,
boolean
3. String can add strings and int can add ints

## Typecasting :

1. Typecasting can change datatype to any


2. Var1= "54" --> print(int(var1)) // This is Typecasting
3. Str(), Int(), Float(), bool()

1. print(10 * string_variable) --> print string valiable 10 times


2. print(10 * int_varibale) --> multiply int to the given multiply number i.e 10

## String Slicing and string Methods or functions :

1. var1 = "Hello World"; print(var1[4]) --> will print 4 letter of string (Only
"O")
2. print(var1[0:4]) --> print Hell
3. print(var1[0:4:2]) --> will print Hl (Skips character
sequence)
4. print(var1[0:]) --> it means [0:n] will print full string
5. print(var1[:5]) --> print from 0 to 4
6. print(var[0::2]) --> will print 0 character upto n with
skip sequence of 1 character
7. print(var[::]) --> it means [0:n:1] will print full
string

1. print(var1[-4:-1]) --> start printing from end or reverse


"orl"
2. print(var1[-4:]) --> print "orld"
3. print(var1[:-1]) --> print "Hello worl"
4. print(var1[::-1]) --> will reverse the whole string
5. print(var1[:-1:-2]) --> reverse the string with one char skip
and exlude d from string

1. print(len(var1)) --> print the length of string


2. print(var1.isalnum()) --> If our string is alphanumeric it print
true and if not false
as our string is hello world which has
spaces so false
3. print(var1.islapha())

1. print(var1.endswith("world")) --> print true as our string ends with


world
2. print(var1.count("o")) --> will tell occurance of "o"
3. print(var1.capitalize()) --> change the first letter of string into
capital
4. print(var1.find("world")) --> find and tell the index that this word
starts from this index
5. print(var1.upper()) --> change whole string into capital
"HELLO WORLD"
6. print(var1.lower()) --> change whole string into small letters
7. print(var1.replace("hello", "hi")) --> output will be "hi world"

You might also like