KEMBAR78
Introduction-to-Python-Programming1.pptx
Introduction to
Python
Programming
Python is a powerful and versatile programming language that has
become increasingly popular in recent years. It's known for its clear
syntax and beginner-friendliness, making it ideal for both learning
and building complex applications. Python has a huge community
of developers, making it easy to find help and resources.
by Vijaya Lakshmi A
Session ObjectivesSession Objectives
• Learning python data types
What is Python?
Python is a high-level, interpreted programming language. Its design focuses
on code readability and simplicity. This makes it easier to write and maintain
code, even for complex projects. Python can be used for various tasks,
including web development, data science, machine learning, scripting, and
more.
Easy to Learn
Python's syntax is intuitive and
straightforward, making it a
great choice for beginners.
Versatile
It can be used for a wide range
of applications, from simple
scripts to complex software.
Large Community
There's a vast community of
Python developers, providing
ample resources and support.
Cross-Platform
Python runs on various
operating systems, including
Windows, macOS, Linux, and
Unix.
Why Learn Python?
Learning Python opens doors to exciting career opportunities and personal projects. With its widespread use, Python skills are highly sought
after in various industries. Furthermore, Python's versatility allows you to explore different areas of programming and pursue your interests.
1 High Demand
Python skills are in high demand in the tech industry, leading
to lucrative career paths.
2 Versatile Applications
Python can be used for web development, data analysis,
automation, and more.
3 Growing Community
The Python community is vast and supportive, providing
abundant resources and help.
4 Open Source
Python is an open-source language, meaning it's free to use
and modify.
• Invented at Netherlands,early 90s by Guido
van Rossum
• Named after Monty Python
• Open sourced, Scalable, object oriented and
functionalProgramminglanguage
• Used by Google as one of its official
programming language
• Increasingly popular
Python - Introduction
Python’s Benevolent Dictator For Life
“Python is an experiment in
how much freedom program-
mers need. Too much freedom
and nobody can read another's
code; too little and expressive-
ness is endangered.”
- Guido van Rossum
http://docs.python.org/
• Call python program via the python interpreter
% python fact.py
• Make a python file directly executable by
–Adding the appropriate path to your python
interpreter as the first line of your file
#!/usr/bin/python
–Making the file executable
% chmod a+x fact.py
–Invoking file from Unix command line
% fact.py
Running Programs on UNIX
• In interactive mode, you type Python programs, and
the interpreter displays the result.
$python 3
>>> 2 + 3
>>> 5
• python3 command enters into python prompt.
• >>> is called the Python prompt in linux.
• The interpreter evaluates the expression and
replies. New prompt indicates it is ready for more
input.
• Working directly in the interpreter is convenient for testing
short bits of code because we get immediate feedback.
Interactive Mode
The set of Python instructions are written in a file called as
program with extension .py also called as script.
The program file is referred as source code.
The compiler is used to convert the source code to byte code.
The interpreter is used to interpret the byte code and produce the
result.
$ g ed i t f i r s t . py
# F i r s t Program
Script Mode
• Indentation matters to code meaning
–Block structure indicated by indentation
• First assignment to a variable creates it
–Variable types don’t need to be declared.
–Python figures out the variable types on its own.
• Assignment is = and comparison is ==
• For numbers + - * / % are as expected
–Special use of + for string concatenation and % for string formatting
(as in C’s printf)
• Logical operators are words (and, or, not) not
symbols
• The basic printing command is print
Enough to Understand the Code
Naming Rules
• Names are case sensitive and cannot
start with a number. They can contain
letters, numbers, and underscores.
bob Bob _bob _2_bob_
bob_2 BoB
• There are some reserved words:
and, assert, break, class,
continue, def, del, elif,
else, except, exec, finally,
for, from, global, if,
import, in, is, lambda, not,
or, pass, print, raise,
return, try, while
Operators and Expressions
Operators are symbols that perform specific operations on values. Expressions are combinations of operators and values that result in a new value. Understanding these is essential for
writing calculations, comparisons, and logical operations.
Operator Description
+ Addition
- Subtraction
* Multiplication
/ Division
== Equality
!= Inequality
< Less than
> Greater than
In Python, the input() function is used to take input from the user. This function reads a line from input (usually
from the keyboard), converts it into a string, and returns it.
Basic Usage of input()
Here is the basic syntax for the input() function:
By default, input() returns a string. If you need to handle other data types (like integers or floats), you'll need to
convert the input using typecasting:
In Python, the print() function is the most commonly used statement for
displaying output. It allows you to print text, variables, and formatted data to the
console.
simple Python program to
add two numbers
Total Salary Calculation
Python Libraries and Frameworks
Python's vast collection of libraries and frameworks extends its capabilities. Libraries provide pre-written code for
various tasks, saving you time and effort. Frameworks provide a structure for building applications, simplifying the
development process.
Web Development
Frameworks like Django and Flask
simplify web application
development.
Data Science
Libraries like NumPy, Pandas, and
Matplotlib are essential for data
analysis and visualization.
Machine Learning
Libraries like scikit-learn, TensorFlow,
and PyTorch empower you to build
machine learning models.
• Python - Introduction
– Interactive Mode
– Script Mode
– Debugging
Summary

Introduction-to-Python-Programming1.pptx

  • 1.
    Introduction to Python Programming Python isa powerful and versatile programming language that has become increasingly popular in recent years. It's known for its clear syntax and beginner-friendliness, making it ideal for both learning and building complex applications. Python has a huge community of developers, making it easy to find help and resources. by Vijaya Lakshmi A
  • 2.
  • 3.
    What is Python? Pythonis a high-level, interpreted programming language. Its design focuses on code readability and simplicity. This makes it easier to write and maintain code, even for complex projects. Python can be used for various tasks, including web development, data science, machine learning, scripting, and more. Easy to Learn Python's syntax is intuitive and straightforward, making it a great choice for beginners. Versatile It can be used for a wide range of applications, from simple scripts to complex software. Large Community There's a vast community of Python developers, providing ample resources and support. Cross-Platform Python runs on various operating systems, including Windows, macOS, Linux, and Unix.
  • 4.
    Why Learn Python? LearningPython opens doors to exciting career opportunities and personal projects. With its widespread use, Python skills are highly sought after in various industries. Furthermore, Python's versatility allows you to explore different areas of programming and pursue your interests. 1 High Demand Python skills are in high demand in the tech industry, leading to lucrative career paths. 2 Versatile Applications Python can be used for web development, data analysis, automation, and more. 3 Growing Community The Python community is vast and supportive, providing abundant resources and help. 4 Open Source Python is an open-source language, meaning it's free to use and modify.
  • 5.
    • Invented atNetherlands,early 90s by Guido van Rossum • Named after Monty Python • Open sourced, Scalable, object oriented and functionalProgramminglanguage • Used by Google as one of its official programming language • Increasingly popular Python - Introduction
  • 6.
    Python’s Benevolent DictatorFor Life “Python is an experiment in how much freedom program- mers need. Too much freedom and nobody can read another's code; too little and expressive- ness is endangered.” - Guido van Rossum
  • 7.
  • 8.
    • Call pythonprogram via the python interpreter % python fact.py • Make a python file directly executable by –Adding the appropriate path to your python interpreter as the first line of your file #!/usr/bin/python –Making the file executable % chmod a+x fact.py –Invoking file from Unix command line % fact.py Running Programs on UNIX
  • 9.
    • In interactivemode, you type Python programs, and the interpreter displays the result. $python 3 >>> 2 + 3 >>> 5 • python3 command enters into python prompt. • >>> is called the Python prompt in linux. • The interpreter evaluates the expression and replies. New prompt indicates it is ready for more input. • Working directly in the interpreter is convenient for testing short bits of code because we get immediate feedback. Interactive Mode
  • 10.
    The set ofPython instructions are written in a file called as program with extension .py also called as script. The program file is referred as source code. The compiler is used to convert the source code to byte code. The interpreter is used to interpret the byte code and produce the result. $ g ed i t f i r s t . py # F i r s t Program Script Mode
  • 11.
    • Indentation mattersto code meaning –Block structure indicated by indentation • First assignment to a variable creates it –Variable types don’t need to be declared. –Python figures out the variable types on its own. • Assignment is = and comparison is == • For numbers + - * / % are as expected –Special use of + for string concatenation and % for string formatting (as in C’s printf) • Logical operators are words (and, or, not) not symbols • The basic printing command is print Enough to Understand the Code
  • 12.
    Naming Rules • Namesare case sensitive and cannot start with a number. They can contain letters, numbers, and underscores. bob Bob _bob _2_bob_ bob_2 BoB • There are some reserved words: and, assert, break, class, continue, def, del, elif, else, except, exec, finally, for, from, global, if, import, in, is, lambda, not, or, pass, print, raise, return, try, while
  • 13.
    Operators and Expressions Operatorsare symbols that perform specific operations on values. Expressions are combinations of operators and values that result in a new value. Understanding these is essential for writing calculations, comparisons, and logical operations. Operator Description + Addition - Subtraction * Multiplication / Division == Equality != Inequality < Less than > Greater than
  • 14.
    In Python, theinput() function is used to take input from the user. This function reads a line from input (usually from the keyboard), converts it into a string, and returns it. Basic Usage of input() Here is the basic syntax for the input() function: By default, input() returns a string. If you need to handle other data types (like integers or floats), you'll need to convert the input using typecasting:
  • 16.
    In Python, theprint() function is the most commonly used statement for displaying output. It allows you to print text, variables, and formatted data to the console.
  • 17.
    simple Python programto add two numbers
  • 18.
  • 19.
    Python Libraries andFrameworks Python's vast collection of libraries and frameworks extends its capabilities. Libraries provide pre-written code for various tasks, saving you time and effort. Frameworks provide a structure for building applications, simplifying the development process. Web Development Frameworks like Django and Flask simplify web application development. Data Science Libraries like NumPy, Pandas, and Matplotlib are essential for data analysis and visualization. Machine Learning Libraries like scikit-learn, TensorFlow, and PyTorch empower you to build machine learning models.
  • 20.
    • Python -Introduction – Interactive Mode – Script Mode – Debugging Summary