2024-10-20 21:20
Status:ongoing
Tags:pythondata-typesoperatorscontrol-structures
Python Scripting
Subject: Introduction to Python
Data Types
flowchart TD
A[Python Data Types]
A --> B[Numeric Types]
B --> C[int]
B --> D[float]
B --> E[complex]
A --> F[Sequence Types]
F --> G[str]
F --> H[list]
F --> I[tuple]
A --> J[Mapping Type]
J --> K[dict]
A --> L[Set Types]
L --> M[set]
A --> N[Boolean Type]
N --> O[bool]
Numeric Types
- int:
int
is short for Integer numbers.- Example:
- float:
- Represents floating-point numbers (numbers with a decimal point).
- Example:
- complex:
- Represents complex numbers, which have a real and an imaginary part.
- Example:
Sequence Types
- str:
str
is short for strings, which are sequences of characters.- Example:
- list:
- An ordered collection of items that can contain a mix of data types. Lists are mutable and written in square brackets.
- Example:
- tuple:
- An ordered collection of items similar to a list, but tuples are immutable and written in parentheses.
- Example:
Mapping Type
- dict:
- A dictionary is an unordered collection of key-value pairs. Each key must be unique.
- Example:
Set Types
- set:
- An unordered collection of unique elements.
- Example:
Boolean Type
- bool:
- A boolean represents one of two values:
True
orFalse
. - Example:
- A boolean represents one of two values:
Operators
Python supports various types of operators:
-
Arithmetic Operators
+
(addition),-
(subtraction),*
(multiplication),/
(division)//
(floor division),%
(modulus),**
(exponentiation)
-
Comparison Operators
==
(equal to),!=
(not equal to)>
(greater than),<
(less than),>=
(greater than or equal to),<=
(less than or equal to)
-
Logical Operators
and
,or
,not
-
Assignment Operators
=
,+=
,-=
,*=
,/=
,%=
,**=
,//=
-
Identity Operators
is
,is not
-
Membership Operators
in
,not in
Control Structures
Control structures direct the flow of your program:
-
Conditional Statements
-
For Loops
-
While Loops
-
Break and Continue
break
: Exits the loopcontinue
: Skips the rest of the current iteration and moves to the next
Next, we’ll explore Functions and Modules in Python to learn how to organize and reuse our code effectively.