Python 3 Refresher — Part 1

>> print(Python is the best!')

2. Common data types

>>> 'hello' * 3 # output: hellohellohello>>> 'hello' + 3 # Error>>> 'hello' + str(3) # hello3>>> 8 / 1 # 8.0>>> 8 // 1 # 8>>> 8 // 1.0 # 8.0>>> 1 + 3j.real # 1.0

3. Abstract data types — data model defined by behavior

List

Set

Tuples

Dictionary or hasmap

4. String formatting

>>> print('Her name is %s. She is %d years old' %('lili', 3))   # Her name is lili. She is 3 years old

5. Classes

class Vehicle:
def __init__(self, name, make, year=2019):
name = self.name
make = self.make
year = self.year
def accelerate:
print('Increasing speed')
# Instantiate car object
>>> bmw = Vehicle('BMW', 'M6', 2012)
>>> print( bmw.make )
# M6

6. Modules and packages

>>> import draw>>> from draw import draw_polygon

Written by

Former Glorified Electrician(aka Electrical Engineer). Now a Software Developer working on complex Enterprise Software. Lets connect on twitter @NdamuleloNemakh

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store