basics of python
basics of python
Topics Covered
• What is Python?
• Variables in Python
• Data Types in python
• Input and Output statements
What is Python?
Python is a popular programming language. It was created by Guido
van Rossum, and released in 1991.
• It is used for:
• web development (server-side),
• software development,
• mathematics,
• system scripting
What can Python do?
• Python can be used on a server to create web applications.
• Python can be used alongside software to create workflows.
• Python can connect to database systems. It can also read and
modify files.
• Python can be used to handle big data and perform complex
mathematics.
• Python can be used for rapid prototyping, or for production-
ready software development.
Why Python?
• Python works on different platforms (Windows, Mac, Linux,
Raspberry Pi, etc).
• Python has a simple syntax similar to the English language.
• Python has syntax that allows developers to write programs with
fewer lines than some other programming languages.
• Python runs on an interpreter system, meaning that code can be
executed as soon as it is written. This means that prototyping can
be very quick.
• Python can be treated in a procedural way, an object-oriented
way or a functional way.
2
Scripts. It will look somehow this :
3
The ” >>> ” represents the python shell and its ready to take python
commands and code.
The Python Command Line
To test a short amount of code in python sometimes it is quickest and
easiest not to write the code in a file. This is made possible because
Python can be run as a command line itself.
Output:
Data Types:
In programming, data type is an important concept.
Variables can store data of different types, and different types can do different
things.
Python has the following data types built-in by default, in these categories:
4
Sequence Types: list, tuple, range
Mapping Type: dict
Set Types: set, frozenset
Boolean Type: bool
Binary Types: bytes, bytearray, memoryview
None Type: NoneType
data types are classifications of data items, which tell the interpreter or compiler
how the programmer intends to use the data. Here are some commonly used
data types in Python along with examples:
1. Integer (int):
Whole numbers without a fractional component.
2. Float (float):
Numbers with a decimal point or in exponential form.
python
3. String (`str`):
Ordered sequence of characters enclosed in single or double quotes.
python
5
4. Boolean (`bool`):
Represents truth values, either `True` or `False`.
5. List (list):
Ordered and mutable collection of elements.
6. Tuple (tuple):
- Ordered and immutable collection of elements.
7. Set (`set`):
- Unordered collection of unique elements.
6
8. Dictionary (`dict`):
Unordered collection of key-value pairs.
9. NoneType (`None`):
Represents the absence of a value or a null value.
These are the basic data types in Python. Keep in mind that Python is dynamically
typed, meaning you don't need to explicitly declare the data type of a variable.
The interpreter infers it based on the assigned value.
Variables in Python
Python has no command for declaring a variable. A variable is created
the moment you first assign a value to it.
Variables are used to store and manage data. Here are some key
points about variables in Python:
1. Variable Assignment:
Variables are created by assigning a value to them using the equal
(`=`) operator.
7
2. Dynamic Typing:
Python is dynamically typed, meaning you don't need to declare the
data type of a variable explicitly. The interpreter infers it based on the
assigned value.
4. Reassignment:
You can change the value of a variable by assigning a new value to
it.
5. Multiple Assignment:
8
You can assign values to multiple variables in a single line.
7. Constants:
Python doesn't have constants in the traditional sense, but it's a
convention to use uppercase names for values that shouldn't be
changed.
8. Deleting Variables:
- You can delete a variable using the `del` keyword.
9
10