Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

1.

Divison (/) always returns a float


2. 17 / 3 -> floor division discards the fractional part
3. 17 % 3 -> % operator returns the remainder of the divison
4. 5 ** 2 -> operator t calcualte powers (25)
5. _ -> it will give the last execute command result
6. print(r'C:\some\name') -> don't want characters prefaced by \ to be interprected
as speical characters, can use raw strings by adding r before the first quote.
7. Strings can be concatenated with the + operator, and repeated with *
Ex : 3 * 'Un' + 'Ium'
Two or more string literals ( ones cnclosed between quotes) next to each other
are automatically concatenated
'py' 'thon' -> python
'py' 'thon' 'training -> pythontraining
8. python strings cannot be changed - they are immutable
9. String fucntions
string.captalize() -> first character captalized and the rest lowercased
string.casefold() -> may be used for caseless matching , similar to
lowercasing but more aggressive it is intended to remove all case distinctions
string.center(width,'fillcharacter') -> return centered in a string of lenght
width , padding is done using the specified fill character, if fillcharacter is not
specified default ASCII space
Ex : string.center(30,"B")
string.center(30)

string.count("changed",stringposition,endposition) -> count fillcharacter


number of times repeated, stringposition and endposition is optional
string.encode() -> endoded version of the string as a bytes object
string.endswith(fillcharacter,startingposition,endposition) -> Return True if
the string ends with the specified fillcharacter
find() -> should be used only if you need to know the position of sub to
check if sub is a substring or not, use in operator
Ex: 'py' in 'python'
string format
"The sum of 1 + 2 is {0}. ". format(1+2) -> 'The sum of 1 + 2 is 3'
strip(fillcharacter) -> string with the leading and training characters
removed , if omitted or None defaults to removing whitespace

10. Multiple assignments


a = b =c =10
a,b,c = 10,20,30

11. String Literals


Formed by enclsoing a text in the quotes
Both single and double quotes can be used
Ex : name1='John'
text1='hello\
world'
multilines='''str1
str2
str3'''

12. Numberic Literals


Unlimited integer sie followed by upper or lowercase L.
Complex numbers form of a+bj , 'a' forms the real part & b forms the
imaginary part.
In python value of integr is not restricted by the number of bits and can
expad to the limit of the available memory

13. Special Literals


None is the python has one speical literal
Used to specify to the filed that is not created

14. Operators
Arithmetic Operators -> + - * / %
Assignment Operators -> = , +=, ==
Comparison Operators
Logical Operators -> and , or , nots
Bitwise Operators -> & , | , >> , << , ~
Identity Operators -> Test if the two operans share an identity is , is not
-> x = 10 x is 10 x is not 10
Membership Operators -> in, not in

15 . Data Type are two types


Immutable (Cannot be changed) -> Numbers,Strings,Tuples
Mutable (Changeable) - > Lists,Sets,Dictionaries

Tuples -> Are a group of values within ()


mygroup = ('a','b','c','d')
tuple1 = ('a','b','c')
tuple1 +=('d',) -> adding item in the tuple

You might also like