currenlty most popular programming language/skill
versatile, powerful , forgiving and easy to learn
'Made for the web'
Goto language for AI, Machine Learning and Data-Science
Example:
print ('Hello World')
Output:
'+ failed_subjects+ '
variable.Example :
Output:
Example :
Output :
interger 2
floating 2.0
Boolean True or False
Standard in python is to use underscore instead capitailation.
"" '' values seens as a string.
escaping \ the caractor after \ just see dont interpret.
b='it's'
Output :
Example:
Output:
Example :
Output:
Example:
Output:
Basic Arithmetic
Addition : 12
Subtraction : 8
Multiplication : 20
Division (float) : 5.0
Division (floor) : 5
Modulus : 0
Exponent : 100
Example:
Output:
Ouput:
Output:
Output:
Output:
Output:
name='TERRY'
color = 'RED'
msg = '[' + name + '] loves the color ' + color + '!'
msg1 = f'[{name}] loves the color {color.lower()}!'
msg2 = f'[{name.capitalize()}] loves the color {color.lower()}!'
print(msg)
print(msg1)
print(msg2)
[TERRY] loves the color RED!
[TERRY] loves the color red!
[Terry] loves the color red!
name= input('What is your name?:')
age=input('What is your age?:')
print('Hello '+ name + '! you are '+ age + 'Years old.')
Output:
What is your name?:suresh
What is your age?:31
Hello suresh! you are 31Years old.
num1=input('Enter a digit: ')
num2=input('Enter a second number:')
answer=float(num1)+float(num2)
print(answer)
Output:
Enter a digit: 12
Enter a second number:34
46.0
take input from user
their first name and distance in km
Print
Greet user by name and show km, and mile values
1 mile is 1.609 kilometers
Output:
Enter your name Suresh
Enter distance in km: 6
Hi Suresh ! 6km is equivalent to 3.7 miles.
List is similar to variable and an list can hold multiple instaces.
friends = ['John','Michael','Terry','Eric','Graham']
print(friends[1],friends[4])
print(len(friends))
print(friends[:])
print(friends[0:2])
print(friends.index('Eric'))
Output:
Michael Graham
5
['John', 'Michael', 'Terry', 'Eric', 'Graham']
['John', 'Michael']
3
Selling Lemonade
Output:
split the string and created a list
Output:
Tuples is actualy a list
change is immutable
less complex and faster then regular list
tupes use pranthathises
sets use curly bracket ,
main difference between list and sets is that sets is un ordered and remove any duplicate.
very fast.
#Sets - blazingly fast unordered Lists
#empty Lists
empty_list = []
empyt_list = list()
#empty Tuple
empty_tuple = ()
empty_tuple = tuple()
#empty Set
empty_set = {} # this is wrong, this is a dictionary
empty_set = set()
text in the code python ignore
Function is way to bundle the code you often use can be reused later.
`def is used to define the functon
In named notation, the arguments are matched to the function parameters by name and can be written in any order.
Some time we need the function to give data/ value back that is return statements.
def value_added_tax(amount):
tax = amount * 0.25
total_amount = amount * 1.25
return [tax, amount, total_amount]
price = value_added_tax(100)
print(price[1],type(price))
[25.0, 100, 125.0] <class 'list'>
100 <class 'list'>
Operator
This will help in make the programs take decisions.
Create a calculator which handles +,-,,/ and outputs answer based on the mode/ operator used
Hint: use 3 separate inputs
Bonus: Extend functionality with extra mode so it also does celsius to fahrenheit conversion
formula is: temp in C9/5 + 32 = temp in f
Output:
loops will run again and again until we say to stop.
Guess the correct number in 3 guesses. If you don’t get it right after 3 guesses you lose the game.
Give user input box: 1. To capture guesses,
print(and input boxes) 1. If user wins 2. If user loses
Tip:( remember you won’t see print statements durng execution, so If you want to see prints during whle loop, then print to the input box
Modification 1: number 1-100, tell user if guess is too high/low ,and let them have 5-10 guesses.
Tip:( remember you won’t see print statements during execution, so If you want to see prints during whle loop, print to the input box (This is specific to this platform)
Nested loop
Name value parsed or key value parsed
my_list = [1,5,3,7,2]
my_dict = {'car':4,'dog':2,'add':3,'bee':1}
my_tuple = ('d','c','e','a','b') # immutable
my_string = 'python'
#print(my_list,'original')
#print(my_list.sort())
#print(my_list,'new')
#print(my_list.reverse())
#print(sorted(my_list))
#my_list1 =sorted(my_list)
#print(my_list1)
#sorting tuple
#print(my_tuple,'new')
#print string
#print(my_string,'original')
#print(sorted(my_string))
#print(my_string,)
print(my_dict,'original')
print(sorted(my_dict.items()))
print(my_dict,'new')
Error handling
Python Inheritance. Inheritance allows us to define a class that inherits all the methods and properties from another class
import modules , program created by other program.
datetime random string os math browser