python_crash_course_notes
python_crash_course_notes
1. :
2. :
3. :
4. ) : )
5. :
6. :
7. : while
8. :
9. :
10. :
11. :
12. :
python.org
Add Python to PATH
:
python --version
#
print("Hello Python world!")
print(" ! .")
# ! : .
:
message = " !"
print(message)
# : !
name = "ali"
print(name.title()) # Ali
print(name.upper()) # ALI
print(name.lower()) # ali
first_name = "ali"
last_name = "ahmadi"
full_name = first_name + " " + last_name
print(full_name) # ali ahmadi
print(2 + 3) # 5
print(3 - 2) # 1
print(2 * 3) # 6
print(3 / 2) # 1.5
print(3 ** 2) # 9
#
print(" # ("!
Name Cases
...
) : )
for
players = [' ' ,' ' ,' ' ,' ' ,' ']
print(players[0:3])
# ' ,' ' ,' '] : ']
:
if, elif, else
age = 12
if age < 4:
print(" ")
elif age < 18:
print(" ")
else:
print(" ")
# :
: while
input
while break/continue
while True:
city = input(" : ")
if city == ' ':
break
print(city)
def greet_user(name):
print(" " + name + "!")
greet_user(" ")
def make_pizza(*toppings):
for topping in toppings:
print(topping)
definition
class Dog:
def __init__(self, name, age):
self.name = name
self.age = age
def sit(self):
print(self.name + " .")
my_dog = Dog('3 ,' )
my_dog.sit()
class ElectricCar(Car):
def __init__(self, make, model, year):
super().__init__(make, model, year)
self.battery_size = 75
with open('file.txt') as f:
contents = f.read()
with open('file.txt', 'w') as f:
f.write(" ")
try:
print(5 / 0)
except ZeroDivisionError:
print(" ")
:
unittest
import unittest
class TestSomething(unittest.TestCase):
def test_something(self):
self.assertEqual(1, 1)
City, Country City, Country, Population ...
:
pygame
: pip install pygame
...