Day 1 Flashcards

1
Q

How are strings concatenated?

A

+ symbol can be used. “part1 “ + “part2”

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

When working with strings, what character is used for newlines and what is the escape character?

A

\n which means that \ is an escape character.

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

Who created Python and why was it created?

A

“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.

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

What is the syntax for printing a string?

A

print(“Example String”)

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

What is the shortcut to the “Run” button?

A

CTRL + Enter

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

What is the shortcut for turning a line into a comment? And how do you undo this?

A

Windows: Ctrl + / And Ctrl + z
Mac: Command + / And “command” + z

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

How do you calculate the number of characters in a string?

A

len(“string”)

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

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)

A

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

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

What is the significance of indentation in Python and what happens if your code starts with a indentation?

A

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/

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

What is the most common website for troubleshooting errors?

A

stackoverflow

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

What is an IDE?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How do you print a string containing the special “ character?

A

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”)’)

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

What is a code block?

A

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.

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

What function is used to prompt the user to enter data?

A

The input function:

input(“Add some string here”)

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

What is nesting in programming and how does it affect the way this code runs?

print(“Hello “+ input(“What is your name”));

A

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.

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

What is a variable?

A

A Python variable is a reserved memory location to store values. In other words, a variable in a python program gives data to the computer for processing. Every value in Python has a datatype.

As the name implies a variable can be changed or varied. So you can change the value of a variable later in the execution of a program.

17
Q

How is a variable assigned a value?

A

With the = operator.