0% found this document useful (0 votes)
6 views10 pages

Introduction To PythonUNIT 1 - PART1

Python is a versatile, high-level programming language known for its simplicity and ease of learning, making it popular in various domains such as web development, game development, and scientific computing. It was created by Guido van Rossum in 1989 and supports multiple programming paradigms, including object-oriented and procedural programming. Python's features include dynamic typing, a large standard library, and strong community support, which contribute to its widespread use in education and industry.

Uploaded by

minnigunta
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views10 pages

Introduction To PythonUNIT 1 - PART1

Python is a versatile, high-level programming language known for its simplicity and ease of learning, making it popular in various domains such as web development, game development, and scientific computing. It was created by Guido van Rossum in 1989 and supports multiple programming paradigms, including object-oriented and procedural programming. Python's features include dynamic typing, a large standard library, and strong community support, which contribute to its widespread use in education and industry.

Uploaded by

minnigunta
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Introduction to python

• python is a general purpose, dynamic, high level, and interpreted


programming language
• it supports object oriented programming approach to develop applications.
• it is simple and easy to learn and provides lots of high level data structures
Applications
[Link] (GUI)CALC
• Image processing and graphic design applications
• Scientific and computational applications
2. Game Development
• Python comes loaded with many useful extensions (libraries) that come in
handy for the development of interactive games.
3 Web Development
Python offers numerous options for web development
4. Scientific and Numeric Applications
Python has become a crucial tool in scientific and numeric computing.

5. Artificial Intelligence and Machine Learning

AI/ML applications require a language that is stable, secure, flexible, and is


equipped with tools that can handle the various unique requirements of such
projects. Python has all these qualities,
6. Software Development
Python packages and applications aim to simplify the process of software
development
7. Enterprise-level/Business Applications
Business applications are designed to fit the requirements of an organization
rather than the needs of individual customers.
8. Education programs and training courses
Python’s easy learning curve and simplicity are the two main reasons why it is
one of the most used programming languages in educational programs, both at
beginner and advanced levels.

HISTORY OF PYTHON
• In 1989 by Guido van Rossum at Centrum Wiskunde & Informatica (CWI)
in the Netherlands as a successor to the ABC language capable of exception
handling and interfacing with the operating system Amoeba.
• Van Rossum is Python's principal author, and his continuing central role
in deciding the direction of Python is reflected in the title given to him by
the Python community, benevolent dictator

• Python 1.0 was released in 1994; it borrowed the module system from
Modula-3, had the capability to interact with Amoeba operating system, and
included functional programming tools.
• SETL is a very high-level programming language based on the mathematical
theory of sets. It was originally developed by Jacob T. Schwartz at the New
York University Courant Institute of Mathematical Sciences in the late 1960s
• He had taken the syntax of ABC, and some of its good features. It came with
a lot of complaints too, so he fixed those issues completely and had created a
good scripting language which had removed all the flaws.
• The inspiration for the name came from BBC’s TV Show – ‘Monty Python’s
Flying Circus’, as he was a big fan of the TV show and also he wanted a short,
unique and slightly mysterious name for his invention and hence he named it
Python!
• He was the “Benevolent dictator for life” (BDFL) until he stepped down from
the position as the leader on 12th July 2018. For quite some time he used to
work for Google, but currently, he is working at Dropbox

What makes Python so special?

• it’s easy to learn – the time needed to learn Python is shorter than for many
other languages; this means that it’s possible to start the actual programming
faster;
• it’s easy to teach – the teaching workload is smaller than that needed by other
languages; this means that the teacher can put more emphasis on general
(language-independent) programming techniques, not wasting energy on
exotic tricks, strange exceptions and incomprehensible rules;
• it’s easy to use for writing new software – it’s often possible to write code
faster when using Python;
• it’s easy to understand – it’s also often easier to understand someone else’s
code faster if it is written in Python;
• it’s easy to obtain, install and deploy – Python is free, open and multiplatform;
not all languages can boast that.
Features of python

• Python is a dynamic, high level, free open source and interpreted


programming language. It supports object-oriented programming as well as
procedural oriented programming.

In Python, we don’t need to declare the type of variable because it is a


dynamically typed language.

1. Easy to code:
Python is a high-level programming language. Python is very easy to learn the
language as compared to other languages like C, C#, Javascript, Java, etc. It is
very easy to code in python language and anybody can learn python basics in
a few hours or days. It is also a developer-friendly language.

[Link] Source and Free

Python is an open-source programming language which means that anyone


can create and contribute to its development. Python has an online forum
where thousands of coders gather daily to improve this language further.
Along with this Python is free to download and use in any operating system,
be it Windows, Mac or Linux.

[Link] for GUI

GUI or Graphical User Interface is one of the key aspects of any programming
language because it has the ability to add flair to code and make the results
more visual. Python has support for a wide array of GUIs which can easily be
imported to the interpreter, thus making this one of the most favorite languages
for developers.

[Link]-Oriented Approach

• One of the key aspects of Python is its object-oriented approach. This basically
means that Python recognizes the concept of class and object encapsulation
thus allowing programs to be efficient in the long run.

[Link]-Level Language

• Python has been designed to be a high-level programming language, which


means that when you code in Python you don’t need to be aware of the coding
structure, architecture as well as memory management.
[Link] Portable

• Suppose you are running Python on Windows and you need to shift the same
to either a Mac or a Linux system, then you can easily achieve the same in
Python without having to worry about changing the code. This is not possible
in other programming languages, thus making Python one of the most portable
languages available in the industry.

[Link] Dynamic

• As mentioned in an earlier paragraph, Python is one of the most dynamic


languages available in the industry today. What this basically means is that the
type of a variable is decided at the run time and not in advance. Due to the
presence of this feature, we do not need to specify the type of the variable
during coding, thus saving time and increasing efficiency.

8. LargeStandardLibrary
Python has a large standard library which provides a rich set of module and
functions so we do not have to write your own code for every single thing.
There are many libraries present in python for such as regular expressions,
unit-testing, web browsers, etc.

• 9. Dynamically Typed Language:


• Python comes inbuilt with a large number of libraries that can be imported at
any instance and be used in a specific program. The presence of libraries also
makes sure that we don’t need to write all the code yourself and can import
the same from those that already exist in the libraries.
• [Link] is Interpreted − Python is processed at runtime by the interpreter.
You do not need to compile your program before executing it. This is similar
to PERL and PHP.
• 11. GUI Programming − Python supports GUI applications that can be
created and ported to many system calls, libraries and windows systems, such
as Windows MFC, Macintosh, and the X Window system of Unix.
• 12. Extendable − We can add low-level modules to the Python interpreter.
These modules enable programmers to add to or customize their tools to be
more efficient.
• 13. Expressive
• Python needs to use only a few lines of code to perform complex tasks. For
example, to display Hello World, you simply need to type one line -
print(“Hello World”). Other languages like Java or C would take up multiple
lines to execute this.
Elements of python program

• comment:The statement which is starting with


# symbol is called comment [Link] line is ignored by the compiler
• Statement:A statement is an instruction that the python
interpreter can execute
• Expression: Expression are the statement which is used for calculation in
programming language
Eg.c=a+b is an expression where the addition of a and b is stored in c.
Expression are formed with operators and operands
• Block or Suite:A block or suite are a group of statements in a program like
control flow statement and looping statement
• Function: The print() or input() function in python are used to send output to
the console window and receive input from the console window
Python Variables

• Variables are containers for storing data values.


• Creating Variables
• Python has no command for declaring a variable.
• A variable is created the moment you first assign a value to it.
Python - Variable Names
• A variable can have a short name (like x and y) or a more descriptive name
(age, carname, total_volume).
• Rules for Python variables:
• A variable name must start with a letter or the underscore character
• A variable name cannot start with a number
• A variable name can only contain alpha-numeric characters and underscores
(A-z, 0-9, and _ )
• Variable names are case-sensitive (age, Age and AGE are three different
variables)
Valid variable names
myvar = "John"
my_var = "John"
_my_var = "John"
myVar = "John"
MYVAR = "John"
myvar2 = "John"
Illegal variable names:
2myvar = "John" #variable name should not start with digit
my-var = "John" # special symbol – not allowed
my var = "John" # space not allowed
Python Variables - Assign Multiple Values
• Many Values to Multiple Variables
• Python allows you to assign values to multiple variables in one line:
• Example
x, y, z = "Orange", "Banana", "Cherry"
print(x)
print(y)
print(z)
One Value to Multiple Variables
• And we can assign the same value to multiple variables in one line:
• Example
x = y = z = "Orange"
print(x)
print(y)
print(z)
Output Variables
• The Python print statement is often used to output variables.
• To combine both text and a variable, Python uses the + character:
• Example
x = "awesome"
print("Python is " + x)
we can also use the + character to add a variable to another variable:
• Example
x = "Python is "
y = "awesome"
z= x+y
print(z)
Python datatypes
• int
• float
• complex
• bool
• str
• list
• tuple
• set
• frozenset
• bytes
• bytearray
• range
• none

• The data type of a variable or object determines which operations can be


applied to it. Once a variable is assigned a data type, it can be used for
computations in the program.
• The best thing about Python is that the data type doesn’t need to be
defined when declaring a variable. Data types exist, but the variables are
not bound to any of them. Languages that act in this way are called
dynamically typed languages.
type(),id(),print()functions

• type(): type() method returns class type of the argument(object) passed


as parameter. type() function is mostly used for debugging purposes.

a=5

type(a)

output:<class ‘int’>
• id():The id() function returns a unique id for the specified object. All
objects in Python has its own unique id. The id is assigned to the object
when it is created.

• print() :The print() function prints the specified message to the screen,
or other standard output device.

In Python, numeric data type represent the data which has numeric value.
Numeric value can be integer, floating number or even complex numbers.
These values are defined as int, float and complex class in Python.
 Integers – This value is represented by int class. It contains positive or
negative whole numbers (without fraction or decimal). In Python there is
no limit to how long an integer value can be.
[Link] form(base-10)
2. binary form(base-2)
[Link] form(base-8)
[Link] form(base-16)

 Float – This value is represented by float class. It is a real number with


floating point representation. It is specified by a decimal point. Optionally,
the character e or E followed by a positive or negative integer may be
appended to specify scientific notation.
 Complex Numbers – Complex number is represented by complex class.
It is specified as (real part) + (imaginary part)j. For example – 2+3j
a = 5
print("Type of a: ", type(a))

b = 5.0
print("\nType of b: ", type(b))

c = 2 + 4j
print("\nType of c: ", type(c))
Output:
Type of a: <class 'int'>

Type of b: <class 'float'>

Type of c: <class 'complex'>


FLOAT
• The number with decimal point is called floating point
• to represent floating point values we go for float data type
• price of petrol 99.81
• Price of diesel 94.03
• dollar value in rupees 72.72
• f=12.4566
• type(f)
<class ‘float’>
• in integers we have
• 1234
• 0B111
• 0o123
• 0x123
for floating points octal binary hexadecimal such type of conventions not
allowed
• f=1.2e3
• this type of representation is called exponential form or scientific
notation
• we can also write E
• 1.2*103
• 1.2*1000=1200.0
Complex data type
• Python specific data type is complex data type
• It is one type of number system
• If we want to develop scientific applications, mathematical based
applications ,electrical engineering applications complex data types
are helpful
• This data type is not available in c,c++,java
how to represent complex number
• a+bj
• a is called real part
• b is called imaginary
• we must use j or J
x=10+20j
type(x)
outout:
<calss ‘complex’>
bool data type
• to represent logical values true or false we go for bool data type
• the only allowed values are True or False
a=True
type(a)
output:
<class ‘bool’>
a,b=10,20
c=a>b
print ( c )
type(c)
output:
False
<class ‘bool’>
str data type
A string is a collection of one or more characters put in a single quote,
double-quote or triple quote. In python there is no character data type, a
character is a string of length one. It is represented by str class.
• String can be represented single quote ,double quotes
• S=‘asdfghh’
• s[begin:end]
• s[:9] 0 to 9
• s[5: ] 5 to end
Accessing elements of String
In Python, individual characters of a String can be accessed by using the
method of Indexing. Indexing allows negative address references to access
characters from the back of the String, e.g. -1 refers to the last character, -2
refers to the second last character and so on.

You might also like