Python Cheat Sheet Codecademy



  • Taking a vacation

    Lesson 01/07 – Before We BeginLesson 02/07 – Planning Your TripLesson 03/07 – Getting ThereLesson 04/07 – TransportationLesson 05/07 – Pull it TogetherLesson 06/07 – Hey, You Never Know!Lesson 07/07 – Plan Your Trip! Lesson 01/07 – Before We Begin […]
    Read More
  • Functions

    Lesson 01/19 – What Good are Functions?!Lesson 02/19 – Function Junction Define your spam function starting on line 5. Youcan leave the code on line 11 alone for now–we’llexplain it soon!Define the spam function above this line.Lesson 03/19 – Call […]
    Read More
  • Date and Time

    Lesson 01/06 – The datetime LibraryLesson 02/06 – Getting the Current Date and TimeLesson 03/06 – Extracting InformationLesson 04/06 – Hot DateLesson 05/06 – Pretty TimeLesson 06/06 – Grand Finale Lesson 01/06 – The datetime Library [code lang=”python”] from datetime […]
    Read More
  • Strings & Console Output

    Lesson 01/16 – StringsSet the variable brian on line 3!Lesson 02/16 – PracticeAssign your variables below, each on its own line!Put your variables above this lineLesson 03/16 – Escaping charactersThe string below is broken. Fix it using the escape backslash!Lesson […]
    Read More
  • Tip Calculator

    Lesson 01/05 – The MealAssign the variable meal the value 44.50 on line 3!Lesson 02/05 – The TaxLesson 03/05 – The TipYou’re almost there! Assign the tip variable on line 5.Lesson 04/05 – Reassign in a Single LineReassign meal on […]
    Read More
  • PygLatin

    Lesson 01/11 – Break It DownLesson 02/11 – Ahoy! (or Should I Say Ahoyay!)Lesson 03/11 – Input!Lesson 04/11 – Check Yourself!Lesson 05/11 – Check Yourself… Some MoreLesson 06/11 – Pop Quiz!Lesson 07/11 – Ay B CLesson 08/11 – Word UpLesson […]
    Read More
  • Python Syntax

    Lesson 01/13 – Welcome!Lesson 02/13 – VariablesWrite your code below!Lesson 03/13 – BooleansSet the variables to the values listed in the instructions!Lesson 04/13 – You’ve Been Reassignedmy_int is set to 7 below. What do you thinkwill happen if we reset […]
    Read More
  • Conditionals & Control Flow

    Lesson 01/15 – Go With The FlowLesson 02/15 – Compare Closely!Lesson 03/15 – Compare… Closelier!Lesson 04/15 – How the Tables Have TurnedLesson 05/15 – To Be and/or Not to BeLesson 06/15 – AndLesson 07/15 – OrLesson 08/15 – NotLesson 09/15 […]
    Read More
  1. Python allows the values in a dictionary to be any type – string, integer, a list, another dictionary, boolean, etc. However, keys must always be an immutable data type, such as strings, numbers, or tuples. In the example code block, you can see that the keys are strings or numbers (int or float). The values, on the other hand, are many varied data types.
  2. Python Cheat Sheet Miscellaneous useful notes 1.extT after a pound sign ( # ), as well as text between sets of three single quotes, ', are comments, and are ignored by the code. 2.extT in parentheses is evaluated by Python prior to other text, in a manner identical to how parentheses are treated in math.
  3. Welcome to Python Cheatsheet! Anyone can forget how to make character classes for a regex, slice a list or do a for loop.This cheat sheet tries to provide a basic reference for beginner and advanced developers, lower the entry barrier for newcomers and help veterans refresh the old tricks.
  4. I'm going through Codecademy's Python 3 course (pro with exercises, projects etc) and I've diligently gone through syntax control flow functions lists and now i'm at the end of loops on the coding challenges and It seems like i'm not able to complete any of the tasks without looking at the solution.

Resource

I've been wanting to update the Beginner's Python Cheat Sheets that accompany Python Crash Course for a while now. I finally made time over the last month to go through the entire set. Pou games gahe. I originally developed the sheets in Word, which was not a particularly sustainable approach.

Download

String

String Methods

File

Methods

Attributes

Set & Mapping

Set Types

  • len(s)
  • x in s
  • x not in s

Mapping Types

  • len(d)
  • d[key]
  • d[key] = value
  • del d[key]
  • key in d
  • key not in d
  • iter(d)

Date Time

Python cheat sheet codecademy

Date Object

Datetime Object

Time Object

Array

Python Cheat Sheet Codecademy

Array Methods

Indexes and Slices

  • a=[0,1,2,3,4,5]
  • 6
  • len(a)
  • 0
  • a[0]
  • 5
  • a[5]
  • 5
  • a[-1]
  • 4
  • a[-2]
  • [1,2,3,4,5]
  • a[1:]
  • [0,1,2,3,4]
  • a[:5]
  • [0,1,2,3]
  • a[:-2]
  • [1,2]
  • a[1:3]
  • [1,2,3,4]
  • a[1:-1]
  • Shallow copy of a
  • b=a[:]

Math

Basic Python Cheat Sheet

Number Theoretic

Power and Logarithmic

Python programming language cheat sheet

Trigonometric Functions

Hyperbolic Functions

Constants

Python Cheat Sheet Codecademy
  • math.pi
  • The mathematical constant π = 3.141592.., to available precision.
  • math.e
  • The mathematical constant e = 2.718281.., to available precision.

Random

Functions

Sys

Sys Variables

  • argv
  • Command line args
  • builtin_module_names
  • Linked C modules
  • byteorder
  • Native byte order
  • check_-interval
  • Signal check frequency
  • exec_prefix
  • Root directory
  • executable
  • Name of executable
  • exitfunc
  • Exit function name
  • modules
  • Loaded modules
  • path
  • Search path
  • platform
  • Current platform
  • stdin, stdout, stderr
  • File objects for I/O
  • version_info
  • Python version info
  • winver
  • Version number

sys.argv

  • foo.py
  • sys.argv[0]
  • bar
  • sys.argv[1]
  • -c
  • sys.argv[2]
  • qux
  • sys.argv[3]
  • --h
  • sys.argv[4]

OS

os Variables

  • altsep
  • Alternative sep
  • curdir
  • Current dir string
  • defpath
  • Default search path
  • devnull
  • Path of null device
  • extsep
  • Extension separator
  • linesep
  • Line separator
  • name
  • Name of OS
  • pardir
  • Parent dir string
  • pathsep
  • Patch separator
  • sep
  • Path separator

Python Cheat Sheet Github

Class

Special Methods

  • __new__(cls)
  • __lt__(self, other)
  • __init__(self, args)
  • __le__(self, other)
  • __del__(self)
  • __gt__(self, other)
  • __repr__(self)
  • __ge__(self, other)
  • __str__(self)
  • __eq__(self, other)
  • __cmp__(self, other)
  • __ne__(self, other)
  • __index__(self)
  • __nonzero__(self)
  • __hash__(self)
  • __getattr__(self, name)
  • __getattribute__(self, name)
  • __setattr__(self, name, attr)
  • __delattr__(self, name)
  • __call__(self, args, kwargs)

String Formatting

Formatting Operations

  • 'd'
  • Signed integer decimal.
  • 'i'
  • Signed integer decimal.
  • 'o'
  • Signed octal value.
  • 'u'
  • Obsolete type – it is identical to 'd'.
  • 'x'
  • Signed hexadecimal (lowercase).
  • 'X'
  • Signed hexadecimal (uppercase).
  • 'e'
  • Floating point exponential format (lowercase).
  • 'E'
  • Floating point exponential format (uppercase).
  • 'f'
  • Floating point decimal format.
  • 'F'
  • Floating point decimal format.
  • 'g'
  • Floating point format. Uses lowercase exponential format if exponent is less than -4 or not less than precision, decimal format otherwise.
  • 'G'
  • Floating point format. Uses uppercase exponential format if exponent is less than -4 or not less than precision, decimal format otherwise.
  • 'c'
  • Single character (accepts integer or single character string).
  • 'r'
  • String (converts any Python object using repr().
  • 's'
  • String (converts any Python object using str()
  • '%'
  • No argument is converted, results in a '%' character in the result.

Date Formatting

Date Formatting

Python Cheat Sheet Pdf

  • %a
  • Abbreviated weekday (Sun)
  • %A
  • Weekday (Sunday)
  • %b
  • Abbreviated month name (Jan)
  • %B
  • Month name (January)
  • %c
  • Date and time
  • %d
  • Day (leading zeros) (01 to 31)
  • %H
  • 24 hour (leading zeros) (00 to 23)
  • %I
  • 12 hour (leading zeros) (01 to 12)
  • %j
  • Day of year (001 to 366)
  • %m
  • Month (01 to 12)
  • %M
  • Minute (00 to 59)
  • %p
  • AM or PM
  • %S
  • Second (00 to 61?)
  • %U
  • Week number1 (00 to 53)
  • %w
  • Weekday2 (0 to 6)
  • %W
  • Week number3 (00 to 53)
  • %x
  • Date
  • %X
  • Time
  • %y
  • Year without century (00 to 99)
  • %Y
  • Year (2008)
  • %Z
  • Time zone (GMT)
  • %%
  • A literal '%' character (%)