Show Menu

Python@Work (By Build-2-Master) Cheat Sheet by

Python Cheat Sheet for Work
python     work

@ Command Line

Python Shell
$ python
Run Script­/File
$ python <fi­len­ame­>.py

Data Types

Boolean
True; False
Numeric
int(str); float(str)
String
'abcdef';
str(nu­mber)
List
['abc', 1, 2];
list(col)
Tuple (cannot update)
('abc', 1, 2);
tuple(col)
Dictionary
{'name': 'john', 'num': 1};
dict['­key'] = val;
obj.__­dict__
Set (unique)
set(col)
- 'col' means collection
 

Operations

Modulus
1 % 2 == 1
Exponent
9 ** 2 == 81
Increment
c += a ~~ c=c+a
Decrement
c -= a ~~ c=c-a
Logical AND
(True and False) == False
Logical OR
(True or False) == True
Membership
1 in [1,2,3] == True;
1 not in [1,2,3] == False
Object
Identity
Obj1 is Obj2

String

Substring
'abcd'­[­1:] == 'bcd';
'abcd'­[­:-1] == 'abc'
Find
str.­fin­d­(ot­herstr)
Check if number
str.­isd­igi­t()
Join
"­-".­jo­in­([­"­a","b­"])
== "­a-b­"
 

String (cont')

Length
len­(str)
Lower, Upper Case
str.­low­er();
str.­upp­er()
Split
"a b".­sp­lit­(­" ")
==['a'­,'b']

List

Index
['a', 'b', 'c']­[1:]
== ['b','c']
Length
len­([­1,2,3]) == 3
Concon­tenate
[1,2] + [3,4] == [1,2,3,4]
Append
[1,2].­a­ppe­nd(3) == [1,2,3]
Pop
[1,2,3­].­po­p(1) == 2
Remove
[1,2,3­].­re­mov­e(1)
Sort
[2,1,3­].­so­rt() == [1,2,3]

Download the Python@Work (By Build-2-Master) Cheat Sheet

1 Page
//media.cheatography.com/storage/thumb/yaohongkok_python-work-by-build-2-master.750.jpg

PDF (recommended)

Alternative Downloads

Share This Cheat Sheet!

Like this cheat sheet? Check out our sponsors!

Readable.io is a collection of tools to make your writing better. More readable content means higher conversion rates and better reader engagement. Measure website and document readability, measure keyword density and more!

Click Here To Get Started!

 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          Web Programming Cheat Sheet
          Essential Python Cheat Sheet