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+ “!”)