Introduction and Variables and Data Types Flashcards
What is the difference between compiled and interpreted languages?
Compiled Languages
1. Code is sent to compiler
2. Compiler translates entire program into code compatible with with target or host machine (Machine Code)
3. Target executes code and return output
Interpreted languages
1. Code read by an interpreter
2. Interpreter returns output without creating executable machine code as independent artifact
What is JupyterLab?
- Integrated development environment
- Facilitates robust development of large Python projects
What is Anaconda?
- Popular distribution packet of Python
- Machine learning and Data sciene
How to access help on functions? Give example with the print function.
help(print())
How do you start interpreter?
Typing:
python
in the interpreter
Explain what a interpreter is
- Program that reads and executes Python code
- Parsing, compiling, and interpreting
Which naming rules exist for variables in python?
Do´s
* Start with letter or underscore
Dont´s
* Existing Variable names
* Reserved words (print, def)
What is wrong $weight = 73
? And which Error would Occur?
- Invalid Syntax error
- Must start with underscore or letter
Which python style naming conventions are there for naming variables?
- All lowercase
- Words separated by underscores
What is the assignment operator and how does he works?
- (=) sign is called an assignment operator
- Assigns value from right-to-left.
What are literals?
- Numbers
- Have the value that they literally and explicitly should have (in this case, 73)
- Cannot be redefined with a different value
How would you scientificaly notate
4.5 x 10^7 ? Explain syientific notation and give an example.
- Represent very large or small numbers
- Commonly used in scientific and engineering fields
4.5e7
How are imaginary numbers represented in Python?
- Build in data type:
complex
complex_number = 1+6J
Write down a hexadecimal
0xFF
- 0x followed by hex part
Write down an Octal
0o23
* Zero followed by lower case o
What is the remainder of:
15 % 6
3
Define String
- Stores text
- In (“”)
- Series of characters (numbers, letters, exclamation etc.)
Is a string mutable?
- Immutable
Mitigation:
* Assign text to new string
Explain why you cant put certain characters in strings and show example of how to mitigate
- Mitigate characters in string that have special meaning in syntax ( “, n, \, r, t)
Escape Characters ()
Escape Sequence (")
Example:
string = "Hello \"Bob\". You count. output = "Hello "Bob". You Count
How would you ignore an escaped string? Explain and write down example
- Raw String
- String prefixed with an r or R
- Tells python to treat strings literally
raw_string = r"This ignores "Bob is \"sad\"" output: "This ignores "Bob is \"sad\""
Demonstrate how to get the index – i.e. the position of a character within a string.
my_string = "Hello, World!" print(my_string.index('e')) output: 1
Demostrate how to count number of matching characters in string
my_string = "Hello, World!" my_string.count('o') output: 2
Demonstrate two ways on concatenating strings
string_one = "Hello" string_two = "World" string_three = string_one + string_two format_string = "Other way {} is {}".format(string_one, other string="like That")
Demostrate how How to replicate the string greeting = "Hello"
4 times? -
print(greeting*4)