Day 1
Concepts, Code Examples and Task
integer
a = 2 b = 3
mathematical operation
print(a+b, a-b, ab, a/b, a//b, a*b) # sum, sub, mul, div, power (2^3)
a > b a < b
strings
a = "shariq" b = "magistersign"
print(a, b) print(a + b)
firstName = "shariq" lastName = "abcd" empty = " "
print(firstName + "|" +lastName) # string concatenation
built-in attributes of print function
print(firstName, lastName, sep = ":")
float
a = 1.1 b = 1.3 print(a + b)
print( 1 + 1.2 ) print("shariq" + 1)
print("shariq"*2)
boolean: True or false
a = False b = True
if conditions, if a == True, while True (infinite)
response = a > b
print(-3//2, -3/2, 23, 22*3) print(22*3)
variable names:
2numnber = 2 # wrong var r = 4 # wrong
var_1 = 2 # right Var = 3 # right secondName = 2
type, int, float, bool, string
type(secondName)
type cast: cast a type (
e = '2' r = int(e) type(r)
e = 2 r = str(e) type(r)
bool(1) bool(0)
input, adding string to integer
user = input("enter an input")
"shariq" + 1
user = int(input("enter integer value"))
eval
user = eval(input("enter value"))
boolean
user = bool(input("enter something"))
r = google.com
e = request("google.com")
comparison types, > ,<, == (to check), = (assignment)
Compare strings
"shariq" == "Shariq" "shariq" == "shariq" "shariq" > "Shariq" "a" > 'A'
character encoding, h (23) -> binary
Task: the difference between ascii code and utf character encoding
ord()
Task:
max number of values in utf vs ascii
which character encoding does your Microsoft word uses
is, in - membership operator
in
or and
"q" in "shariq" # sharik, sharique 1 and 0 or 1
1 or 0
False or False and True
Last updated
Was this helpful?