- Python has several build in commands to easy the day to day programming.
- Check here for available built in functions.
- Boolean are handled in python in a bit different way. Normal convention is to use
trueandfalsefor boolean. But in Python we useTrueandFalse
- In python to represent Null we use
None. Pay attention to capitalN
finallyblock intryandexceptwork exactly the same asfinallyblock in Javaelseblock can be used to perform an action when there is no exception.raisekeyword is use to throw an exception.
- math
- os
- random
- sys
- re
- json
- datetime
inputis the function used to take user input.- The value return by
inputfunction is string. - You should convert the return from
inputcall to whatever you expect as input.
age = input("enter your age:") # enter 30
type(age) # will return string
age = int(age) # Convert it to type which you expect.
type(age) # will return int- capitalize - Change to upper case the first letter of the string.
- title - Change to upper case first letter of all the words in the string
- upper - Change all chars in the string to upper case
- lower - change all chars in the string to lower case
- count - return the total number of given char in the string. case sensitive.
- find - return the position of a char in the string.
- split - split the string based on the separator provided.
- Tuple is immutable ordered list. Can contain duplicates.
- Tuple elements are access in same fashion as list.
- Tuple are created using parenthesis in place of square brackets as in list.
primes = (3,7,11)
primes[0]my_list = [1,2,3,45,56]
print(my_list[2:4]) # prints 3, 45
print(my_list[2:]) # prints 3, 45,56
print(my_list[:4]) # prints 1,2,3,45
print(my_list[::1]) # prints 1,2,3,45,56
print(my_list[::2]) # prints 1,3,56
print(my_list[2::2]) # prints 3,56
print(my_list[1:4:2]) # prints 2,45classmethodandstaticmethodbehave a bit similarly.- Difference is a class method will take a class reference as argument along with other argument(if needed), where are in
@staticmethodno argument are mandatory.