chapter_two Flashcards
What does a name error in traceback indicate?
1) forgot to set the variable’s value
2) made a spelling mistake when entering the variable’s name.
How do you name variables?
1) can contain only letters, numbers and underscores
2) can’t start with a number
3) spaces are not allowed, use underscores instead
4) avoid Python keywords and function names
5) avoid “l” and “O” because of their similarities with “1” and “0”
6) short and desciptive naming ( n_l < name_of_persons_name < name_lenght)
What are variables and their properties?
1) Lables that you can assign to values
2) references a certain value.
3) The value can be changed any time
What does the “Python interpreter” do?
1) It interpretes the code you wrote
2) translates into a simpler language for the computer to understand.
> “Hello World!”
What kind of data type is this?
What defines that data type?
1) A “string”
2) defined as a series of characters
3) enclosed by a pair of quotation marks.
4) Either single ‘ ‘ or double “ “ quotes can be used.
> string = “hello world!”
How do you capitalize every first letter of this string?
Give a short description about the functionality of your code.
1) > string.title( )
2) The “.title( )” method appears after a variable.
3) It changes each word to title case, where each word begins with a capital letter.
What is a method?
How is it structured?
What is the functionality of said structure?
1) An action that Python can perform on a piece of data.
2) a dot “ . “ connects the method to a variable
3) a set of parentheses ends the method
4) the method acts on the variable it is connected to
5) the parentheses can be used to insert additional information a method might need
> message = “Hello World!”
Which code would you insert above to get the same output as shown below?
> > > hello world!
HELLO WORLD!
> message = “Hello World!”
1)
> print( message.lower( ) )
2)
> print( message.upper( ) )
> name = “Thomas”
How would you insert the variable above into a string?
What is the name for the code you used? short and long version.
What is the reason for its name?
> name = “Thomas”
1) f” “
2) {name}
> string = f”Hello, {name}!”
3) “f-string”.
4) The “f” stands for “format”
5) Python formats the string by replacing the name of any variable in braces with its value.
What is whitespace ?
Insert two variantes of whitespace in the string below.
> string = “Hello World!”
1) any nonprinting character
2) ex. spaces, tabs and end-of-line symbols.
3)
> string = “Hello\n\tWorld!”
4) \t - tab; \n - new line
> string = “ whitespace “
how would you remove the whitespace
- to the left end
- to the right end
- on both ends
1)
> string.rstrip( )
2)
> string.lstrip( )
3)
> string.strip( )
What is a syntax error?
1) occurs when Python doesn’t recoginze a section of your program
2) as valid Python code.
How would you insert the following two sentences in a string?
- One of Python’s strenghts is its diverse community. -
- He said, “fishsticks”, and we all started laughing. -
Why do it that way?
1)
> “One of Python’s strenghts is its diverse community.”
2)
> ‘He said, “fishsticks”, and we all started laughing.’
3) You can’t use the quote your are using to enclose the string in the text or it will cause errors.
What are “integers” and what operators can be used in combindation with them?
How do you write exponents in Python?
1) Integers are a data type in Python consisting of whole numbers.
2) You can add (+), subtract (-), multipy (*) and divide (/) integers in Pyhon.
3) Python uses two multiplication symbols to represent exponents (**)
What are “floats”?
What are their irregularities?
1) Python calls any number with a decimal point a float
2) Floats can sometimes get an arbitrary number of decimal places in your answers.
3) Python tries to find a way to represent the result as precisely as possible
4) sometimes difficult given how computers have to represent numbers internally.