0% found this document useful (0 votes)
26 views18 pages

Introduction to Python Programming

The document discusses Python programming including introduction to Python, variables, data types, operations, loops and functions. It explains that Python is a popular programming language created in 1991. Variables in Python don't require data type declaration. Python has built-in data structures like lists, dictionaries, tuples and sets. The document also covers arithmetic, assignment, comparison, logical and other operators in Python.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views18 pages

Introduction to Python Programming

The document discusses Python programming including introduction to Python, variables, data types, operations, loops and functions. It explains that Python is a popular programming language created in 1991. Variables in Python don't require data type declaration. Python has built-in data structures like lists, dictionaries, tuples and sets. The document also covers arithmetic, assignment, comparison, logical and other operators in Python.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

Jb Institute of technology

Python
programming

Submitted by –
Divyanshi Agarwal
Btech cse 2nd year
Lets learn about python programming!!!

 Introduction to Python
 Using variables in Python
 Basics of Python Programming
 Datatypes in python
 Operations in Python
 Loops in Python
 Functions in Python
INTRODUCTION TO PYTHON

 PYTHON is a popular programming language. It was created by Guido van


Rossum, and released in 1991and further developed by the Python Software
Foundation. It was designed with an emphasis on code readability, and its
syntax allows programmers to express their concepts in fewer lines of code.
 Python is a high-level, general-purpose and a very popular programming
language. Python programming language (latest Python 3) is being used in web
development, Machine Learning applications, along with all cutting edge
technology in Software Industry.
 Python is a programming language that lets you work quickly and
integrate systems more efficiently.
 There are two major Python versions: Python 2 and Python 3.
Both are quite different.
For example:-

# To print hello world:-

#output:-
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
[Link], you can think it as a Python’s IDE
to run the Python Scripts. It will look somehow
this :
[Link] you are on Linux/Unix-like just open the terminal and on 99% linux OS
Python comes preinstalled with the [Link] type ‘python3’ in terminal and you
are ready to go. It will look like this :
Variables and data structure in python
 In other programming languages like C, C++, and Java, you will need to declare the type of variables but
in Python you don’t need to do that. Just type in the variable and when values will be given to it, then it
will automatically know whether the value given would be an int, float, or char or even a String.
 See, how simple is it, just create a variable and assign it any value you want and then use the print function
to print it. Python have 4 types of built-in Data Structures namely List, Dictionary, Tuple, and Set.
 List is the most basic Data Structure in python. List is a mutable data structure i.e items can be added to
list later after the list creation. It’s like you are going to shop at the local market and made a list of some
items and later on you can add more and more items to the list.
BASICS OF PYTHON
PROGRAMMING
 What Are Variables In Python?
 Variables and data types in python as the name suggests are
the values that vary. In a programming language, a variable is a
memory location where you store a value. The value that you
have stored may change in the future according to the
specifications.
 What are constants in Python?
 Constants are literals which contain a value which is not supposed to
be changed during the execution of the program.
DATA TYPES
Operators in Python
 Python divides the operators in the following groups:
• Arithmetic operators
• Assignment operators
• Comparison operators
• Logical operators
• Identity operators
• Membership operators
• Bitwise operators
LOOPS IN PYTHON

 Python provides three ways for executing the loops.


While all the ways provide similar basic functionality,
they differ in their syntax and condition checking time .
o WHILE LOOP
o FOR LOOP
WHILE LOOP
While Loop in Python
In python, a while loop is used to execute a block of statements
repeatedly until a given condition is satisfied. And when the condition
becomes false, the line immediately after the loop in the
program is executed.
Syntax :
while expression: statement(s)
FOR LOOP
For Loop in Python
For loops are used for sequential traversal.
For example: traversing a list or string or array etc.
In Python, there is no C style for loop, i.e., for (i=0; i<n; i++).
There is “for in” loop which is similar to for each loop in other
languages.
Let us learn how to use for in loop for sequential traversals.
Syntax:
for iterator_var in sequence: statements(s)
FUNCTIONS IN PYTHON
 A function is a block of code which only runs when it is called.
 You can pass data, known as parameters, into a function.
 A function can return data as a result.
CALLING BY A
FUNCTION
To call a function, use the function name followed by parenthesis:
Example:
def my_function():
print("Hello from a function")

my_function()
OUTPUT:

Hello from a functiona function lo from a function


PYTHON APPLICATIONS
Thank you!!!

Common questions

Powered by AI

Python operators include arithmetic operators (e.g., +, -, *), assignment operators (e.g., =, +=, -=), comparison operators (e.g., ==, !=, >), logical operators (e.g., and, or), identity operators (e.g., is, is not), membership operators (e.g., in, not in), and bitwise operators (e.g., &, |). In a simple program, arithmetic operators might be used for calculating sums, logical operators for flow control decisions, and membership operators for checking item presence in collections .

Code readability is a principal design philosophy in Python, aiming to make code clear and easy to understand. Python's syntax enhances readability by using indentation instead of braces to delineate code blocks, favoring explicit identifiers, and supporting a style guide, PEP 8, that encourages uniform formatting. These features help maintain consistent, readable code, which is easier to review and debug, fostering better collaboration and fewer errors during development .

Lists in Python are mutable, meaning their contents can be changed after creation by adding, removing, or modifying elements. This makes them highly versatile for operations that require changeability. In contrast, tuples are immutable, so once a tuple is created, it cannot be altered. This immutability makes tuples more suitable for use cases where data integrity is essential, and the overhead of potential changes needs to be minimized .

Python's suitability for system integration tasks stems from its high-level nature and wide array of powerful libraries and frameworks that facilitate communication between different system components. Python's extensive support for third-party libraries, along with its capabilities in network programming, data serialization, and process control, make it ideal for integrating disparate systems efficiently. Its interoperability with other programming languages and platforms enhances its utility, allowing for seamless system integration .

Constants in Python are a conventionally used way to define values that are intended to remain unchanged throughout the program's execution. Although Python does not enforce constant behavior, by using uppercase naming conventions, developers can signal that certain variables should not be modified. Using constants helps prevent unintentional value changes, aiding in maintaining consistency and reducing errors within the code .

Python's dynamic typing system means that variables do not have a fixed type and can be assigned to different data types over time. It automatically determines the type of the variable during runtime based on the value assigned to it. This offers flexibility and ease of use since programmers do not need to declare types explicitly, allowing for faster development and code that is easier to read and maintain .

Loops in Python facilitate the repeated execution of a block of code as long as a condition is met. The 'while' loop executes statements repeatedly as long as a given boolean condition is true, making it suitable for scenarios where iteration needs to occur until a specific condition changes. The 'for' loop is used for iterating over a sequence (like a list or a string) and is ideal for situations where the number of iterations is defined by the dataset being looped over .

Python 2 and Python 3 differ in several significant ways, such as print statements: Python 2 uses 'print' as a statement, whereas Python 3 uses it as a function. Additionally, Python 3 emphasizes Unicode by default, while Python 2 does not. Choosing the correct version is crucial because Python 3 is the future of Python programming and includes many improvements, such as better language consistency and newer libraries that are not available in Python 2. Python 2 has been officially discontinued and no longer receives updates or support .

Functions in Python are defined using the 'def' keyword followed by the function name and parentheses, which may include parameters. The function body consists of indented statements, and functions can return data using a 'return' statement. For example, a function to add two numbers can be defined as 'def add(a, b): return a + b'. This function can then be called with two numbers to get their sum, such as 'sum = add(2, 3)', which will assign 5 to the variable 'sum' .

Python can be used across various domains in modern software development, including web development with frameworks like Django, data analysis with libraries such as pandas, and machine learning through tools like TensorFlow and Scikit-learn. Its benefits include an extensive standard library, a large community offering extensive documentation and support, and the capability to integrate with other languages and platforms. Python's simplicity and readability also make it a preferred choice for rapid application development and prototyping .

You might also like