Python Basics
Python Basics
Data types
Variables
Expression
String operations
Data types
Data types
Numbers
Strings
Boolean
Numbers
10
11.2
2 + 5j
Number type conversion
int(5.32) 5
float(11) 11.0
complex(10) 10 + 0j
String
"40"
'Hello'
"Hello"
Boolean
Variables
Variables
Variables are containers for
storing data values
variables
To create a variable, you simply need
to assign a value to a name using the
assignment operator (=)
Rules for python variable
variable names in Python have to start with a letter or an underscore
They cannot start with a number
They can't contain any special characters other than an underscore
Variable names are case-sensitive (age, Age and AGE are three different variables)
Expressions
Arithmetic expression
Relational expression
Assignment expression
Logical expression
or
and
not
Identity expression
Membrership expression
String operations
Length of a string
Indexing
string slicing
string concatenation
"Hello" "world" "Hello world"
string format
we cannot combine strings and
"His age is" 20 numbers
But we can combine strings
and numbers by using the
format method
placeholders should be created
with {}
Find the index
This will return the
index position of the
specified string
Count
This will return the
number of occurances
of specified string
Capitalize
The first character is converted
to upper case, and the rest are
converted to lower case
Upper
It converts all characters
present in the string into
upper case
Lower
It converts all characters
present in the string into
lower case
Replace
This method replaces a
specified string with another
specified string.
Replace
The count can also be
mentioned to specify how
many occurrences of the
old value you want to
replace.
Split
This will split each word into
separate strings
Split
You can also
specify where to
split
Center
This method will center
allign the string based on
the specified length
Find
It finds the index of
first occurance of
specified string
Find
You can also metion
between the starting
and ending index
rFind
rfind is similar to find,
but rfind searches
from right side
Strip
This will remove the
specified string in
starting and ending
position