Skip to content

Instantly share code, notes, and snippets.

@elmahdim
Last active December 14, 2017 13:59
Show Gist options
  • Save elmahdim/1835555cb2e43f187a5fe6931a2ae290 to your computer and use it in GitHub Desktop.
Save elmahdim/1835555cb2e43f187a5fe6931a2ae290 to your computer and use it in GitHub Desktop.
Python 3 Cheatsheet

Identifiers

A Python identifier is a name used to identify a variable, function, class, module or other object. Python does not allow punctuation characters such as @, $, and % within identifiers. Python is a case sensitive programming language.

Naming conventions

  • Class names start with an uppercase letter. All other identifiers start with a lowercase letter.
  • Starting an identifier with a single leading underscore indicates that the identifier is private.
  • Starting an identifier with two leading underscores indicates a strong private identifier.
  • If the identifier also ends with two trailing underscores, the identifier is a language-defined special name.

Lines and Indentation

Python does not use braces({}) to indicate blocks of code for class and function definitions or flow control. Blocks of code are denoted by line indentation.

if True:
   print ("True")

else:
   print ("False")

Quotation

Python accepts single ('), double (") and triple (''' or """) quotes to denote string literals. The triple quotes are used to span the string across multiple lines.

print('.')
print("..")
print ("""...
....""")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment