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.