-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex22.py
35 lines (29 loc) · 2.24 KB
/
ex22.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# All exercises symbols and words written down and reviewed from exercise 1 to 21
# Powershell [Environment]::SetEnvironmentVariable - Change an environmental variable in the registry for the current user
# ls - list directory
# cd - change directory
# $env:path - environmental variable indicating a list of paths that the OS will search when executing a file from powershell
# ctrl+z - exit python in command line
# Print "String" - Print a string to command line output
# python ex1.py - run a python script in command line
# OPERATORS - + - / * % (modulus returns the remainder of a division problem. E.G. 7 % 3 = 1
# NAME = "STRING" - a name is a python variable and can be declared as it is given a value
# Print can concatenate strings using "String 1" + var1 + "String 2"
# Print can include formats such a "this is a decimal %d" % 10
# Formatters include %r (literal), %s (string), %d (decimal), %f (float)
# escape characters can include \n (newline) \r (carriage return) \" (escape symbol for quote) \% (escape modulus) \\ (escape slash) \t (Tab)
# Print can use """ for multi-line printing
# Adding a comma after a print command makes the next print command print to the same line
# raw_input(prompt) prints a prompt and returns user input
# from module import identifier - imports the identifier identifier from the module module
# argv - argument variable in the sys module that allows for command line runtime arguments. It is typically unpacked within the code as arg1, arg2, = argv
# open(File) will open a file, it can include the secondary arguments w/r/a for read/write/append. Adding a + allows read/write on these arguments.
# file.read() will output the contents of a text file
# file.open(file, 'w') will truncate contents of the file and allow writing
# file.write(line) will write to a line in the file. if mode is append it will appear at the end of the file.
# file.seek(0) will place the i/o at the first byte of the file
# file.writelines() will write multiple strings to a file
# file.readline() will read a single line from the file and advance the I/O
# def function(args) will define a new function with arguments in it
# return will return a value from that function
# def function(): needs a colon at the end and the code in the function will be indented