Python
Note 1: To see builtin funtions use below command:
dir(__builtins__)
Note 2: Python is case sensitive language
Note 3: To find builtin function functionality
Help(<builtin function>)
Note 4: There are multiple modules in python. To work with these
use below command to import modules.
Import <module name> ex: math
Ex: [Link](9)
User Input in Python: To read input values from prompt:
Ex: Variable = Name
Name = input(Enter your name: )
Print(Your Name is : +Name)
Converting sting to number:
Ex: Variable = age
age = int(input(Enter your age: ))
Print(Your age is: +age)
Concatenate string:
Ex: Print(Hello + World)
Converting number to string:
Ex: Print(Your age is: + str(28)) Or
Print(Your age is: +28)
Arithmetic Operations:
Ex:
5+5
55
5 / 3 -- Divide
5 % 3 -- Remainder (Modulo)
Conditional Statements:
IF:
name = "fish"
if name is "fish":
print("this is a fish");
Tab space is required for print
IF Else:
age = 25
if age > 50:
print("No need to see movies")
elif age < 17 and age > 12:
print("can see a rated PG-13 movie")
elif age == 25:
print("Can see all movies")
else:
print("can only see rated PG movie")
List: list that are less than 5.
a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
num = int(input("Chose a number: "))
new_list = []
for i in a:
if i < num:
new_list.append(i)
print(new_list);
Division:
num = int(input("Please choose a number to divide: "))
listRange = list(range(1,num+1))
divisorList = []
for number in listRange:
if num % number == 0:
[Link](number)
print(divisorList)