mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2025-12-19 10:07:46 -05:00
fix(curriculum): add data types explanation for python lesson (#64541)
Co-authored-by: Dario <105294544+Dario-DC@users.noreply.github.com> Co-authored-by: Krzysztof G. <60067306+gikf@users.noreply.github.com>
This commit is contained in:
@@ -7,6 +7,8 @@ dashedName: what-are-common-data-types-in-python-and-how-do-you-get-the-type-of-
|
|||||||
|
|
||||||
# --description--
|
# --description--
|
||||||
|
|
||||||
|
Before working with Python variables, it's important to understand data types. A data type describes the kind of value a variable holds. For example, a number, a piece of text, or a list of items. Programming languages use data types so they know how to store and work with different kinds of information.
|
||||||
|
|
||||||
Python is a dynamically-typed language like JavaScript, meaning you don't need to explicitly declare types for variables. The language knows what data type a variable is based on what you assign to it.
|
Python is a dynamically-typed language like JavaScript, meaning you don't need to explicitly declare types for variables. The language knows what data type a variable is based on what you assign to it.
|
||||||
|
|
||||||
Here are some examples:
|
Here are some examples:
|
||||||
@@ -25,6 +27,18 @@ int age = 25
|
|||||||
|
|
||||||
The dynamic-typing nature of Python makes coding really fast and more flexible, but it can lead to unexpected bugs because type errors are detected only when a program runs, not when the program compiles.
|
The dynamic-typing nature of Python makes coding really fast and more flexible, but it can lead to unexpected bugs because type errors are detected only when a program runs, not when the program compiles.
|
||||||
|
|
||||||
|
Since Python determines data types while your program is **running**, type-related mistakes are only discovered at that moment. When a program runs, Python executes your code line by line. If it reaches a line where a certain object is expected to behave in a way it's not able to, Python will stop and show an error.
|
||||||
|
|
||||||
|
In contrast, some languages **compile** your program before it runs. Compiling means the computer checks your code in advance and prepares it to run. During this step, those languages can catch type errors before the program even starts.
|
||||||
|
|
||||||
|
You don't need to know those languages yet. The important idea is simply:
|
||||||
|
|
||||||
|
- **In Python type errors can reveal themselves during execution**, when the program is actually running and using your code.
|
||||||
|
|
||||||
|
- **Compiled languages catch type errors during the compile step**, before the program is allowed to run.
|
||||||
|
|
||||||
|
Because of this, you might not learn about a type mistake in Python until the program reaches that specific line of code while running.
|
||||||
|
|
||||||
Here are the most common data types you'll use in Python:
|
Here are the most common data types you'll use in Python:
|
||||||
|
|
||||||
- Integer: A whole number without decimals, for example, `10` or `-5`.
|
- Integer: A whole number without decimals, for example, `10` or `-5`.
|
||||||
|
|||||||
Reference in New Issue
Block a user