-
Notifications
You must be signed in to change notification settings - Fork 0
Python basics
Nikolina Djekic edited this page Apr 10, 2020
·
1 revision
- Comments
- Importing Modules
- Strings
- Advanced strings
- Math
- Variables & Methods
- Functions
- Boolean Expressions
- Relational operators
- Conditional Statements
- Lists
- Touples
- Dictionaries
- Looping
- Sockets
# this is a comment
From what import what as alias
#sys, os, datetime often used
# Alias if defined instead of writing datetime, you can wtite dt if specified
print("string")
print('string')
print("""String
multiple lines""")
print("string 1 " + "is awesome")
[0] #first letter
[-] #last letter
.split() #splits words into list
.join
# escaping \
.strip() # strip spaces
print("Sentence {}".format(variable)) #concatenating
- */+- all supported
- ** exponents
- % modulo
- // -dividing without leftovers
variable_name = value
#Method call with dot . Ex.
value.upper()
.upper()
.lower()
.title()
.len(variable) #broj karaktera
.int() #returns integer, does not round!
.float() # returns float
.type()
#defining functions
def function_name(params):
variables with indentation
# Calling function
function_name(params)
True, False
AND OR
if:
else:
if:
elif:
else:
- []
- Live in brackets
- Can be changed
list_name = [list_items, "separated by comma"]
# [index] - starts from 0
# [start_index:end_index]
# [start:] - everything after starting index
# [:stop] - everything until stop index
# [-1] - very last item
.len()
.append(what) #at end
.pop(index) #delete last or (index)
- ()
- Unchangeable
- Can just be printed or read
tuple_name = (list_items, 'separated by comma')
- {}
- Key, value
var_name = {key:value, key:value, key: [values, values]}
employees[key] = [value] # adding
.update({"key": [values]}) # adding
.get(key) # returns value
for x in list:
print(x)
while condition:
# what_happens
iteraror ++
- To connect 2 ports together
- Connecting ports and ip addreses
- Connect to open port etc.
s= socket.socket(socket.AD_INET, socket.SOCK_STREAM)
Written by Ninna94