0% found this document useful (0 votes)
0 views

basics of python

Uploaded by

Arnav Rajesh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

basics of python

Uploaded by

Arnav Rajesh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

DAY-1

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.

Introduction and Setup


1. If you are on Windows OS download Python by Clicking
here and now install from the setup and in the start menu type
IDLE.IDLE, you can think it as a Python’s IDE to run the Python

2
Scripts. It will look somehow this :

2. If you are on Linux/Unix-like just open the terminal and on 99%


linux OS Python comes preinstalled with the OS.Just type
‘python3’ in terminal and you are ready to go. It will look like
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.

Input and Output


In this section, we will learn how to take input from the user and hence
manipulate it or simply display it. input() function is used to take input
from the user and the print() function to output text to the console.
Program:

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:

Text Type: str


Numeric Types: int, float, complex

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.

3. Variable Naming Rules:


1. Variable names can consist of letters, numbers, and underscores
but cannot start with a number.
2. Variable names are case-sensitive.
3. Avoid using reserved words (keywords) as variable names.
Example:

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.

6. Global and Local Scope:


Variables defined outside of functions have a global scope, while those
defined inside functions have a local scope.

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.

Understanding how to use variables effectively is fundamental to


writing readable and maintainable Python code.

9
10

You might also like