Introduction and Variables and Data Types Flashcards

1
Q

What is the difference between compiled and interpreted languages?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is JupyterLab?

A
  • Integrated development environment
  • Facilitates robust development of large Python projects
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is Anaconda?

A
  • Popular distribution packet of Python
  • Machine learning and Data sciene
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How to access help on functions? Give example with the print function.

A
help(print())
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you start interpreter?

A

Typing:

python

in the interpreter

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Explain what a interpreter is

A
  • Program that reads and executes Python code
  • Parsing, compiling, and interpreting
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Which naming rules exist for variables in python?

A

Do´s
* Start with letter or underscore

Dont´s
* Existing Variable names
* Reserved words (print, def)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is wrong $weight = 73 ? And which Error would Occur?

A
  • Invalid Syntax error
  • Must start with underscore or letter
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Which python style naming conventions are there for naming variables?

A
  • All lowercase
  • Words separated by underscores
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the assignment operator and how does he works?

A
  • (=) sign is called an assignment operator
  • Assigns value from right-to-left.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are literals?

A
  • Numbers
  • Have the value that they literally and explicitly should have (in this case, 73)
  • Cannot be redefined with a different value
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How would you scientificaly notate
4.5 x 10^7 ? Explain syientific notation and give an example.

A
  • Represent very large or small numbers
  • Commonly used in scientific and engineering fields
4.5e7
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How are imaginary numbers represented in Python?

A
  • Build in data type:
    ~~~
    complex
    ~~~
    ```
    complex_number = 1+6J
    ~~~
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Write down a hexadecimal

A
0xFF
  • 0x followed by hex part
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Write down an Octal

A

0o23
* Zero followed by lower case o

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the remainder of:
~~~
15 % 6
~~~

A

3

17
Q

Define String

A
  • Stores text
  • In (“”)
  • Series of characters (numbers, letters, exclamation etc.)
18
Q

Is a string mutable?

A
  • Immutable

Mitigation:
* Assign text to new string

19
Q

Explain why you cant put certain characters in strings and show example of how to mitigate

A
  • 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
20
Q

How would you ignore an escaped string? Explain and write down example

A
  • 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\""
21
Q

Demonstrate how to get the index – i.e. the position of a character within a string.

A
my_string = "Hello, World!"
print(my_string.index('e'))

output: 1
22
Q

Demostrate how to count number of matching characters in string

A
my_string = "Hello, World!"
my_string.count('o')

output: 2
23
Q

Demonstrate two ways on concatenating strings

A
string_one = "Hello"
string_two = "World"

string_three = string_one + string_two

format_string = "Other way {} is {}".format(string_one, other string="like That")
24
Q

Demostrate how How to replicate the string greeting = "Hello" 4 times? -

A
print(greeting*4)
25
Q

Demonstrate the use of all substring operations using all three operators with the example string Hello

A

The first operator indicates start. Without additional parameters, it will only return character.

example_string = "Hello"
print(example_string[1])

output: e

The second character is (:). It indicates the end. Left without third parameter, it will output the rest of string

print(example_string[1:]
output: llo

print(example_string[1:3]
output: ll

The third parameter in the substring operation is the step. The step allows you to specify an increment that identifies characters to be returned in the substring. Think of it as “return every xth character.”

print(example_string[0::2]

output: hlo

print(exampe_string[0::4]

output: l
26
Q

Demonstrate how to insert a string between every letter of another string

A
print(("-").join("TEST"))

output: T-E-S-T
27
Q

Demostrate how to split a string in its components and return list. Explain the method you use

A
print("This is a String".split(" "))

The .split(“ “) method is called on the string. The split() method is used to divide a string into a list of substrings based on a specified delimiter. In this case, the delimiter is a space character “ “.

28
Q

Demonstrate how to replace a character or substring within a string with another character or substring

A
print("Python is amazin".replace("is", "grüfti"))

output: Python is grüfti
29
Q

Demonstrate how you would put quotes into a string in Python

A
my_string = “this has \”quotes\”.”