Python Overall Flashcards
What is a Value in Python?
A value is one of the basic things a program works with. A value can be a letter or a number. Examples of values are 1, 2, and ‘Hello, World!’
What are examples of Value Types?
2 is an integer, and ‘Hello, World!’ is a string, so-called because it contains a “string” of letters.
How can we identify strings? because they are enclosed in quotation marks.
You can identify strings because they are enclosed in quotation marks. Python gives us the freedom to use either single or double quotes, so the string ‘Hello, World’ and “Hello, World!” are the same string. Note, however, that we must begin and end every string with the same type of quotation mark.
(True or False) Commas act as separators in Python.
True
What does a Print Statement allow us to do?
The print statement allows us to display both strings and integers when we run the created program.
(True or False) If you are not sure of your Value Type, the Python Interpreter can tell you the values when you run your program.
True
What is the type code for String?
str
What is the type code for Integers?
int
In Python, numbers with a decimal point belong to a type called?
float
What is a Float?
Numbers with a decimal point belong to a type called float because these numbers are represented in a format called floating-point.
How do you identify types in Python?
By calling the type function into your statement - E.g. print(type(“Hello World!”)) This will define the type for you.
(True or False) When using underscores in large numbers underscores are included.
False
(True or False) A variable is a name that refers to a value.
True
What can be used for Variable names?
They can contain letters, numbers, and underscores. However, they cannot start with a number. Although it is legal to use uppercase letters, it is customary to use all lower-case letters in variables names.
(True or False) The underscore character _ can appear in a name.
True. It is often used in names with multiple words, such as my_name, etc. Variable names can start with an underscore character, but we generally avoid doing this unless we are writing library code for others to use.
What is a Syntax error?
Python can only execute a program if the syntax is correct; otherwise, the interpreter displays an error message. Syntax refers to the structure of a program and the rules about that structure. For example, parentheses have to come in matching pairs, so (1 + 2) is legal, but 8) is a syntax error. If there is a single syntax error anywhere in your program, Python will display an error message and quit, and you will not be able to run your program.
What is a Runtime error?
This error does not appear until after the program has started running. These errors are also called exceptions because they usually indicate that something exceptional (and bad) has happened.
What is a Semantic error?
If there is a semantic error in your program, it will run successfully in the sense that the computer will not generate any error messages, but it will not do the right thing. It will do something else. Specifically, it will do what you told it to do.
The problem is that the program you wrote is not the program you wanted to write. The meaning of the program (its semantics) is wrong. Identifying semantic errors can be tricky because it requires you to work backward by looking at the output of the program and trying to figure out what it is doing.
Explain the Python String identifier() Method.
A string is considered a valid identifier if it only contains alphanumeric letters (a-z) and (0-9), or underscores (_). A valid identifier cannot start with a number, or contain any spaces.
Python has a number of other keywords or reserved words. Explain.
The keywords or reserve words are used to define the syntax and structure of the Python language. In Python, keywords are case-sensitive. There are 33 keywords in Python 3.7. This number can vary slightly over the course of time.
Python reserves 31 keywords for its use:
This is the list(however it may vary):
and - del - from - as - elif - global - assert - else - if - break - except - import - class - exec - in - continue - finally - is - def - for - lambda not - while - or - with - pass - yield - print - raise - return - try