-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathvariables-handling
More file actions
67 lines (56 loc) · 1.33 KB
/
variables-handling
File metadata and controls
67 lines (56 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#input
stringin = input("enter some input. ")
intin =int(input("enter numer input "))
print (type(stringin))
print (type(intin))
#assignments
x = 5
y = "Peter"
z = 5.0
t = True
print(x," ",y, " ",z, " ", t)
print(type(x)," ", type(y), " ", type(z), " ", type(t))
#indexing a string
index0 = stringin[0]
index1 = stringin[1]
print("index", index0)
print("index", index1)
#casting or "retyping"
#stringin = int(stringin)
print ("recast stringin",type(stringin))
num1 = input("enter first num ")
num2 = input("enter second num ")
num3 = num1 + num2
print ("num3"," ", num3)
num4 = int(num1)+int(num2)
print ("num4"," ", num4)
#operations on strings
stringin = str(stringin)
op1 = stringin[0]
op2 = stringin[1]
print("op1:", type(op1),op1)
print("op2:", type(op2),op2)
opsum = int(op1) + int(op2)
print("opsum:", opsum)
# run the above with numbers as well as chars in stringin and see error.
#operations on booleans
x = 5
y = 5
result = x == y
# result is True because x and y have the same value
x = True
y = False
result = x and y # result is False
x = True
y = False
result = x or y # result is True
x = True
result = not x # result is False
x = 5
y = 10
result = x < y # result is True
my_list = [1, 2, 3]
result = 2 in my_list # result is True
x = [1, 2, 3]
y = [1, 2, 3]
result = x is y # result is False (they are two different objects)