Python Programming Codes & Syntax:
For data Printing:
Syntax:print(‘Hello’) # we can use ( ‘ ) or ( “ )
Bonus:
name1 = "Firoz"
name2 = "Rehan"
print(f"Hello there {name1} and {name2}") # Hello there Firoz and Rehan- It is a newer way to do things as of python 3.6 and above.
print("Hello there {}, {}".format(name1, name2)) # Hello there Firoz and Rehan
print("Hello there %s and %s" %(name1, name2)) # Hello there Firoz and Rehan
=>in the same way we can use "%d" & "%f " for integers & floats representations respectively.
For data Input
Syntax
value = input(‘Enter the text ’) # we can use ( ‘ ) or ( “ )For Storing the inputted value
Syntax:
name = input(“Enter you name: “)
print(“Hi “, name) # we can use ( , ) or ( + )
“Hello”' + “World” # “Hello World” --> this is called string concatenation
For any programming language we must be aware of following terminologies:
1. "Terms", that are being used in that language to communicate with other programmers.
Example: instance, parameter, passing values et cetera.
2. Language “Data Type", what type of data a program can hold.
3. “Action”, like receiving the data and performing the action on that to generate the output.
Python Fundamental Data Type:
1. int - for whole integer type (Ex: 2, 5, 9, 12, 1500)
Syntax:
x=5print(x) # 5print(type(x)) # int
2. float - for float or number in decimal type. (Ex: 10.5, 56.50, 8.005)
Syntax:
3. bool - for TRUE or FALSE type.
Syntax:
4. str - for string type ( Ex: "Hello World")
Syntax:
5. list - It is a collection of data (number or string) that is ordered and changeable and written with square brackets.
Syntax:
6. tuple - It is a collection of data (number or string) that is ordered and unchangeable. and written with round brackets.
Syntax:
Syntax:
x=5.005print(x) # 5.005print(type(x)) # float
3. bool - for TRUE or FALSE type.
Syntax:
print( 5 < 9 ) # TRUEprint( 5 > 9 ) # FLASE
4. str - for string type ( Ex: "Hello World")
Syntax:
x=" Hello World"print(x)print(type(x)) # str
5. list - It is a collection of data (number or string) that is ordered and changeable and written with square brackets.
Syntax:
list1 = ["Hello" , "World" , "I" , "am" , 0+1]
print(list1) # ['Hello', 'World', 'I', 'am', 1]
print(type(list1)) # list
Syntax:
tuples = ("Hello" , "World" , "I" , "am" , 0+1)
print(list1) # ('Hello', 'World', 'I', 'am', 1)
print(type(list1)) # tuple
7. set -It is a collection unordered, unindexed, and changeable data (number or string). and written with curly brackets. Unordered means whenever we call set, the element will not print in sequence ie in random order.
Syntax:
sets= {"Hello" , "World" , "I" , "am" , 0+1}
print(sets) # {1, 'World', 'I', 'Hello', 'am'} at every execution the sesqence would be randon
print(type(sets)) # set
8. dict - It is a collection of data that is unordered, changeable, indexed, and they have keys and values. and written with curly brackets.
Syntax:
dicts = {
"brand" : "Hyundai",
"model" : "Accent",
"year" : 2011
}print(dicts) # {'brand': 'Hyundai', 'model': 'Accent', 'year': '2011'} at every execution the sequence would be randomprint(dicts["model"]) # Accent
Updating.....
0 Comments