Course 7 - Python Flashcards
is how you make a comment in Python
Python uses several data types. We’ll focus on string, float, integer, Boolean, and list data.
String data is data consisting of an ordered sequence of characters. These characters could be letters, symbols, spaces, and even numbers. Numbers in the string data type cannot be used for calculations. All characters in a string must be placed inside quotation marks. Luckily, Python will tell you by giving you an error message if you forget a quotation mark.
Float data is data consisting of a number with a decimal point. This includes fractions like 2.1 or 10.5. It also includes whole numbers with a decimal point like 2.0 or 10.0.
Integer data is data consisting of a number that does not include a decimal point. Numbers such as 0, -9, and 5,000 are valid integers.
We can use print with float and integer data to perform all kinds of mathematical operations like addition, subtraction, multiplication, and division.
Boolean data is data that can only be one of two values: either True or False. Booleans are useful for logic in our programs.
And the last data type we’ll cover is lists. List data is a data structure that consists of a collection of data in sequential form.
We need to place the list in brackets. After this, we place the individual items in the list in quotation marks and separate them with commas.
A variable is a container that stores data.
To create a variable, you need a name for it. Then, you add an equals sign and then an object to store in it. Creating a variable is often called assignment. The best practice for naming variables is to make the names relevant to what they’re being used for.
But if we could use the string directly, why do we need variables? Well, we often use variables to simplify our code or make it cleaner and easier to read. Or if we needed a very long string or number, storing it in a variable would let us use it throughout our code without typing it all out. In the previous example, the variable stored string data, but variables can store a variety of data types. Variables have the data type of the object currently storing them.
A type error is an error that results from using the wrong data type.
Earlier, we mentioned how variables are like containers. What they hold can change. After we define a variable, we can always change the object inside of it. This is called reassignment. Reassigning a variable is very similar to assigning it in the first place.
The loop variable is a variable that is used to control the iterations of a loop. The loop variable comes directly after for. A common name for it is the letter i, but you can give it any other name you want.
An important detail about the range function is that if we don’t provide a start point, it automatically starts from zero
Automation: The use of technology to reduce human and manual effort to perform common and repetitive tasks
Boolean data: Data that can only be one of two values: either True or False
Command-line interface: A text-based user interface that uses commands to interact with the computer
Comment: A note programmers make about the intention behind their code
Conditional statement: A statement that evaluates code to determine if it meets a specified set of conditions
Data type: A category for a particular type of data item
Dictionary data: Data that consists of one or more key-value pairs
Float data: Data consisting of a number with a decimal point
Integer data: Data consisting of a number that does not include a decimal point
Integrated development environment (IDE): A software application for writing code that provides editing assistance and error correction tools
Interpreter: A computer program that translates Python code into runnable instructions line by line
Iterative statement: Code that repeatedly executes a set of instructions
List data: Data structure that consists of a collection of data in sequential form
Loop variable: A variable that is used to control the iterations of a loop
Notebook: An online interface for writing, storing, and running code
Programming: A process that can be used to create a specific set of instructions for a computer to execute tasks
Set data: Data that consists of an unordered collection of unique values
String data: Data consisting of an ordered sequence of characters
Syntax: The rules that determine what is correctly structured in a computing language
Tuple data: Data structure that consists of a collection of data that cannot be changed
Type error: An error that results from using the wrong data type
Variable: A container that stores data
A __________ is a section of code that can be reused in a program.
function
Built-in functions are functions that exist within Python and can be called directly. They are available to us by default.
User-defined functions are functions that programmers design for their specific needs.