Day 1 Flashcards
How are strings concatenated?
+ symbol can be used. “part1 “ + “part2”
When working with strings, what character is used for newlines and what is the escape character?
\n which means that \ is an escape character.
Who created Python and why was it created?
“Guido van Rossum”
in 1991. It was created to solve some of the problems with the interpreted language, ABC, most importantly not being extensible enough.
What is the syntax for printing a string?
print(“Example String”)
What is the shortcut to the “Run” button?
CTRL + Enter
What is the shortcut for turning a line into a comment? And how do you undo this?
Windows: Ctrl + / And Ctrl + z
Mac: Command + / And “command” + z
How do you calculate the number of characters in a string?
len(“string”)
Which of the following is the correct way to name a variable?
a. user name = input(“what is your name? “)
b. user_name = input(“what is your name? “)
c. length4 = len(name)
d. 4length = len(name)
b. Spaces are not permitted, must be replaced by underscore
c. Numbers are permitted, but only at the end of words, not the beginning.
Note: don’t use function words (input, print etc.)to name variables
What is the significance of indentation in Python and what happens if your code starts with a indentation?
Indentation in Python refers to the (spaces and tabs) that are used at the beginning of a statement. The statements with the same indentation belong to the same group called a suite.
In most other programming languages, indentation is used only to help make the code look pretty. But in Python, it is required for indicating what block of code a statement belongs to.
If you start with an space or tab in your first line you will get a “indentationError: undexpected indent”
https://www.w3schools.in/python-tutorial/concept-of-indentation-in-python/
What is the most common website for troubleshooting errors?
stackoverflow
What is an IDE?
An integrated development environment (IDE) is software for building applications that combines common developer tools into a single graphical user interface (GUI).
In this course we started just using replit to code, but the most common one out there is Visual Studio Code.
How do you print a string containing the special “ character?
With the escape character \ you can make “ part of the string. Eg:
print(“String Concatenation is done with the "+" sign.”)
Or you can start the string with a ‘ instead of a “. E.g:
print(‘e.g. print(“Hello “ + “world”)’)
What is a code block?
In Python, code block refers to a collection of code that is in the same block or indent. This is most commonly found in classes, functions, and loops.
A code block can be more than a one-liner. All lines with the same indentation belong to the same code block.
What function is used to prompt the user to enter data?
The input function:
input(“Add some string here”)
What is nesting in programming and how does it affect the way this code runs?
print(“Hello “+ input(“What is your name”));
Nesting occurs when one programming construct is included within another.
In the code example the print function starts executing, but before it can complete the program reaches the input function nested inside the print function. The input function is executed completely before the print function can complete. It lets the user enter their name and concatenates that with the “Hello “ to print the result “Hello Jana” as the print function completes.