Python 101

Data Structures

Bruno Vieira

Overview

Arithmetic operators

Arithmetic examples: + - * /



Arithmetic examples: / //



Arithmetic examples: ** and operators style



PEP 8 -- Style Guide for Python Code

Arithmetic examples



Arithmetic examples



Variables

"...a variable is a storage location and an associated symbolic name..." in Wikipedia

Assignment statement



This is different from the equal operator ==



Variables usefulness



Variables usefulness



Variables forbidden names

The following identifiers are used as reserved words, or keywords of the language, and cannot be used as ordinary identifiers.

and       del       from      not       while
as        elif      global    or        with
assert    else      if        pass      yield
break     except    import    print     None
class     exec      in        raise     _*
continue  finally   is        return    __*__
def       for       lambda    try       __*

More information

Python Documentation: Identifiers

Assignment operators

Assignment examples





Assignment examples



Assignment examples



Data types

More information

Python Documentation

Integers and floats

Integers and floats assignment



Strings

Strings assignment



Strings assignment

Please try the following lines in the editor below

print "hello world"
print 'hello world'
print 'hello" "world'
print "hello' 'world"
print 'hello"
print "world'


Strings assignment multiline

""" or '''


Integers + Strings



Integers * Strings



Strings slices

variable = "string"
variable[start:stop:step]


Strings slices



Strings slices with negative indices



Strings slices with steps



Strings slices out of range



 

Strings methods

Strings methods

capitalize center count decode encode endswith expandtabs find format index isalnum isalpha isdigit islower isspace istitle isupper join ljust lower lstrip partition replace rfind rindex rjust rpartition rsplit rstrip split splitlines startswith strip swapcase title translate upper zfill

Total: 38

CHALLENGE FAILED

Strings methods

count endswith find islower isupper join lower lstrip replace rfind rsplit rstrip split splitlines startswith strip swapcase translate upper

Total: 19

CHALLENGE CONSIDERED

Strings methods

Total: 10


CHALLENGE ACCEPTED

Strings methods

More information

Python Documentation

String count

str.count(sub[, start[, end]])




String replace

str.replace(old, new[, count])




String translate

str.translate(table[, deletechars])
string.maketrans(from, to)




String startswith and endswith

str.startswith(suffix[, start[, end]])




String find and rfind

str.find(sub[, start[, end]])




String islower and isupper

str.islower()


String lower, upper and swapcase

str.lower()




String join

str.join(iterable)


String strip, lstrip and rstrip

str.strip([chars])


Data Structures

Lists

Lists assignment

[a, b, c]


Lists assignment



[1] Python Built-in Functions

Lists assignment

str.split([sep[, maxsplit]])




Lists assignment

str.splitlines([keepends])


Lists assignment

str.splitlines([keepends])


Lists are a mutable sequence type





Multi-dimensional lists



Lists methods

More information

Python Documentation

Lists count, index, append and insert



Lists remove



Lists pop



Lists reverse and sort



Lists with Python Built-in Functions



More information

Python Documentation

Lists with join



Data Structures

Tuples

More information

Python Docs: Tuples and Sequences

Tuples assignment



Data Structures

Sets

More information

Python Docs: Sets

Sets



Sets



Data Structures

Dictionaries

Dictionaries assignment

{'a': 1, 'b': 2, 'c': 3}
{'key1': "Value", 'key2': "Value", 1: "Another Value", 'd': 42}


Dictionaries assignment



Wrap up

/

#