Python Basics - 01
Python Basics - 01
Hello Class!
1.0.2 Variables
Variables are containers for storing data values.
Python has no command for declaring a variable.
A variable is created the moment you first assign a value to it.
Variable names are case-sensitive.
String variables can be declared either by using single or double quotes:
[41]: x = 5
str = 'Hello, World!'
y = 6
print(x+y)
11
[9]: print(str)
Hello, World!
1
Lists are one of 4 built-in data types in Python used to store collections of data, the
other 3 are Tuple, Set, and Dictionary, all with different qualities and usage.
print(thislist)
[14]: print(thislist[1])
banana
Loop List
[17]: for x in thislist:
print(x)
apple
banana
cherry
[19]: print(thislist)
[22]: print(thistuple[3])
apple
2
1.0.5 Python Sets
Set items are unordered, unchangeable, and do not allow duplicate values.
[23]: thisset = {"apple", "banana", "cherry", "apple"}
print(thisset)
Ford
Update Dictionary
[27]: thisdict.update({"color": "red"})
Loop Dictionaries
[28]: for x in thisdict:
print(thisdict[x])
Ford
Mustang
1964
red
Ford
Mustang
1964
red
[31]: print(thisdict)
3
brand Ford
model Mustang
year 1964
color red
1
2
3
4
5
6
7
8
9
If Else
[40]: x = 3
y = 2
if x>y:
print("x is greater than y")
else:
print("y is greater than x")
x is greater than y
2
3
4
5
2
5
8
11
4
14
17
20
23
26
29
[ ]: