PYTHON
cheat sheet for the AI and ML
RUDHRA Pratp Singh
DAY 1
print("hey i am a good boy Rudhra ")
# print
# comment---single line : # symbol
escape sequence --
\”- for using the double qourts in printing
\’ -for using the single qourts in printing
\n - to change the line
\t- for tab
\\- for the backslash
DATA TYPES
Operation on python
addition (+)
subtration(-)
divison (/)
miltiplication (*)
float divison (//) - it removes the floting values after the divison.
modulous (%)
TYPE CASTING TYPE OF TYPE CASTING
1) ecplecit high to low
2) implesit:low to high by the using
@ funtion ara
*int()
*float()
* str()
*ord()
*hex()
*oct()
*tuple()
*set()
*list()
*dict()
etc
Input : function
form the input fucntion
String
strings are immutable
* [Link]()--changes into upper case
* [Link]()--changes the string into lower case
* len(a)--finds the length of the string
* [Link]("!")--------- stip the back charaters passed as a perimeter |n not he front once
eg:- !!!rudhra!!!!
output:- !!!rudhra
* [Link]("_word which you want to replace _","_word form which you want to replace_")
-- it repaces the word
* [Link](" ")---- coverts into the list
* [Link]() -- to capitlize thefirst character
* [Link]() --to aline the string in a string method
* [Link]("__parimeter__")---- it counts the number of occurence of the chatracter inside
the string
* [Link]() --it tells weather the stering is ending with that character or not
* [Link]() --it serch and tells the first occurence of the parameter passed in paranthasis
if the passed chareter is not found the output will be -1
* [Link]() --it is simelar to the find|||| if the passed chareter is not found the output will be [er
]
* [Link]() -- it will check weather the string is alpha-numberic order or not
it return true whenthe whole string is written in the alphanumaric order {A-Z,a-z,0-
* [Link]() -- same as the isnum(){A-Z,a-z}
* [Link]() -- weather the all the characters are inlower case or not
* [Link]()---------- it return true when the all the character in the string (eg:-rudhra \n)
* [Link]() -- it return true only when trer is a wide space (eg:- rudhra pris )
Return True if the string is a whitespace string, False otherwise.
conditional statements .
here in python indentation is
syntax
must for the block declration
if(condition):
space to enter inside the block
else :
statment
conditional operators :
< if(conditon):
<= statements
> elif(conditon ):
>= steaements
== elif(condition):
!= statements
else:
statements
LIST
mylist=[1,2,3,4,"rudhra",5.6]
lists : it is a collection of the items lists are mutable
syntax:- list_name=[item1,item2,item3,...] we can change the items in the list
mylist[0]=100
eg:- mylist=[1,2,3,4,"rudhra",5.6]
print(mylist)
to access the items in the list
output:-[100,2,3,4,"rudhra",5.6]
print(mylist[0])
output:-1
list sclicing print(mylist[1:4])
in the slicing the last index is excluded
output:-[2,3,4]
* [Link](item)---- it adds the item at the end of the list
* [Link](index,item)---- it adds the item at the specified index
* [Link](item)---- it removes the specified item from the list
* [Link](index)---- it removes the item at the specified index
* [Link]()---- it sorts the list in ascending order
* [Link]()---- , it reverses the list
* [Link](item)---- it counts the number of occurrences of the specified item in the
list
* [Link]()---- it removes all the items from the list
* len(mylist)---- it returns the number of items in the list
* [Link](another_list)---- it adds the items of another list to the end of the list
* [Link](item)---- it returns the index of the first occurrence of the specified item in
the list
* [Link]()---- it returns a copy of the list
* del mylist[index]---- it deletes the item at the specified index
* del mylist---- it deletes the entire list