0% found this document useful (0 votes)
11 views7 pages

python_crash_course_notes

The document is a Python Crash Course that covers various programming concepts including basic syntax, data types, control structures, functions, and object-oriented programming. It provides examples of code snippets for printing messages, performing arithmetic operations, using lists and dictionaries, and defining classes. Additionally, it touches on file handling and error handling in Python.

Uploaded by

Xps M
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views7 pages

python_crash_course_notes

The document is a Python Crash Course that covers various programming concepts including basic syntax, data types, control structures, functions, and object-oriented programming. It provides examples of code snippets for printing messages, performing arithmetic operations, using lists and dictionaries, and defining classes. Additionally, it touches on file handling and error handling in Python.

Uploaded by

Xps M
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Python Crash Course ( )

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!")

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
...

bicycles = ['trek', 'cannondale', 'redline', 'specialized']


print(bicycles)
# : ['trek', 'cannondale', 'redline', 'specialized']
motorcycles = ['honda', 'yamaha', 'suzuki']
motorcycles.append('ducati')
print(motorcycles)
# : ['honda', 'yamaha', 'suzuki', 'ducati']

Names Greetings Guest List Dinner Guests ...

) : )
for

names = [' ' ,' ' ,' ']


for name in names:
print(" " + name + "!")
# : ! ...

range list comprehensions

squares = [value ** 2 for value in range(1, 11)]


print(squares)
# 100 ... ,9 ,4 ,1] : ]

players = [' ' ,' ' ,' ' ,' ' ,' ']
print(players[0:3])
# ' ,' ' ,' '] : ']

dimensions = (200, 50)


print(dimensions[0])
# 200 :

Pizzas Animals Counting to Twenty Cubes ...

:
if, elif, else
age = 12
if age < 4:
print(" ")
elif age < 18:
print(" ")
else:
print(" ")
# :

if age > 18 and ' ' in fruits:


print(" ")

Conditional Tests Alien Colors Stages of Life ...

alien_0 = {'color': 'green', 'points': 5}


print(alien_0['color'])
# : green

for key, value in alien_0.items():


print(key, value)

Person Favorite Numbers Glossary Rivers ...

: while
input

age = int(input(" "))


if age >= 18:
print(" ")

while break/continue
while True:
city = input(" : ")
if city == ' ':
break
print(city)

Rental Car Restaurant Seating Pizza Toppings ...

def greet_user(name):
print(" " + name + "!")
greet_user(" ")

def get_formatted_name(first, last):


return first + ' ' + last
gfn = get_formatted_name('ali', 'ahmadi')
print(gfn)

def make_pizza(*toppings):
for topping in toppings:
print(topping)

Message Favorite Book T-Shirt Album Sandwiches ...

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

Restaurant Users Admin & Privileges Battery Upgrade ...

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(" ")

Cats and Dogs Common Words ...

:
unittest

import unittest
class TestSomething(unittest.TestCase):
def test_something(self):
self.assertEqual(1, 1)
City, Country City, Country, Population ...

:
pygame
: pip install pygame
...

Star Pattern ...

Python Crash Course


. .

You might also like