Anda di halaman 1dari 12

Python Features Overview

ADSA Advanced Workshops Fall 2018

bit.ly/CrashCourseADSA
bit.ly/ADSAPythonRefresh
Python Basics
- Variables
- Logic & Conditionals

Refresher -
-
Lists
Loops
- Functions

Notebook: https://goo.gl/gqLJCv
Variables
- Not strongly typed
- Built in Python functions that work across most
variable types
- Cast a variable to a different type
- Null/NaN values
- Swapping values between variables
Logic &
- Python uses the full words for most logical
operators

Conditionals -
-
False, True
and, or, not, in for logical comparisons
- !=, ==, <, >= for variable comparisons
- Full list can be found online
- Conditional statements perform the same as
most other programming languages
- if, elif, else
Lists
- Extremely powerful variable type in Python
- Declared with a comma separated sequence of
items surrounded by two brackets
- Access an item in the list by index
- Indices start from 0
- .append(), .insert(), .remove(), .index()
- List slicing
- List operators can be found online
Loops
- for and while loops as well as any nested
combination
- range([start], stop[, step]) (More info online)
- “for each” loops (More info online)
for <variable> in <sequence>:
- break, continue, and pass statements
Functions
- def and pass
- Standard parameters
- Default/optional parameters
Advanced Python
- List Comprehension
- Tuples

Features -
-
Dictionaries
Collections

Notebook: https://goo.gl/CtnVph
Python List
- Concise way to create lists
- [ expression for item in list if conditional ]

Comprehension - Many examples in the notebook


Tuples
- (X1, X2, X3, …, Xn)
- Like an immutable list
- len()
- Return multiple values in a function
Dictionaries
- List that is unordered, mutable, and indexed
- Elements are key : value pairs
- Fast access of elements when you know the key
- Iterate over items with for-each syntax
for key, value in mydict.items():
(key & value are just variable names in this
case)
- Get a list of just values/keys with values() or
keys()
- Common use is for string formatting
Collections
- High performance container datatypes as
alternatives to standard dict, list, set, & tuple
- namedtuple()
- Counter
- OrderedDict
- Read about others online