basics Flashcards
exponentiation
**
variable
A variable is a named memory location. Think of a
variable as a box.
It contains a value. Think of the value as the
contents of the box.
What does the assignment statement r = 10 do?
It creates a variable r and assigns it the value of 10.
What can the first character of a variable name be?
It must be a letter (a-z, A-Z) or an underscore (_).
What characters can be used in the remaining part of a variable name?
Letters, numbers (0-9), and underscores (_)
Are variable names in Python case sensitive?
Yes, x and X are considered two different variables.
Which of the following are valid variable names? radius, 1stValue, _value, Total$, data123
radius and _value are valid; 1stValue, Total$, and data123 are invalid.
int
numbers as integers.
float
numbers as decimals
string
A string is a sequence of characters
enclosed within
Given s = ‘The Beatles’, what is s[4]?
s[4] is ‘B’.
What is string slicing?
Slicing allows you to extract a portion of a string by specifying a range of indices.
What does t = s[4:8] return for s = ‘The Beatles’?
t becomes ‘Beat’
print with operator
print(“Hello,” + “world”)
print with operator
username=”Lisa”
print(“Hello,” + username+ “!”)
print with f strings
username=”Lisa”
print(f”Hello,{Username} !”)
\n
prints out a new line
\t
prints out tab
boolean
true or false
What is a syntax error?
A syntax error refers to issues with the structure of a program, violating the rules of the programming language.
When does the interpreter check for syntax errors?
The interpreter checks for syntax errors during the parsing stage before executing the code.
What is a runtime error?
A runtime error occurs after the program has started running and typically indicates an exceptional situation.
What is a logical error?
A logical error, also known as a semantic error, occurs when there is a mistake in the program’s logic, leading to incorrect results.