Skip to content

Instantly share code, notes, and snippets.

@imralpharvin
Last active September 13, 2020 18:13
Show Gist options
  • Select an option

  • Save imralpharvin/1e34f8241c50232e9d27762d767fdd32 to your computer and use it in GitHub Desktop.

Select an option

Save imralpharvin/1e34f8241c50232e9d27762d767fdd32 to your computer and use it in GitHub Desktop.
Phyton Notes

Python

Use launcher from command line:

py

Quit launcher:

exit()

Run script in terminal:

helloworld.py

To comment:

#This is a comment

To print:

print()

To print integers with strings:

str()

To get input:

input("Please input: ")

Multiple input:

input("Please enter inputs: ").split()

for loop:

for i in list:

while:

while condition:

else in python loop:

can be used to execute if for loop did not break or is exhausted

pass:

does nothing

to define function:

def fib(n):

newline:

\n

Multi-line comment:

"""
line 1
line 2
"""

concept of default argument values:

def func(arg, num = 1, string = "This is a string")

You can call this function by putting only the mandatory arguments

func("mandatory")

intermezzo coding style:

4-space indentation
limit of 79 characters per line
blank lines to separate functions

list:

catNames = ['Naruto','Sasuke']

append to list:

catNames.append(cat)

remove from list:

catNames.remove(cat)

stack:

same as list

appent to stack:

same as list

queue:

collection.deque
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment