0% found this document useful (0 votes)
2 views34 pages

Intro to Python

The document provides an introduction to Python, covering its definition, history, advantages, applications, and installation. It explains basic concepts such as data types, variables, objects, classes, and functions, along with rules for naming variables and using comments. Additionally, it highlights popular websites built with Python and offers guidance on running Python code and using its IDE.

Uploaded by

shweta1bgsws
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)
2 views34 pages

Intro to Python

The document provides an introduction to Python, covering its definition, history, advantages, applications, and installation. It explains basic concepts such as data types, variables, objects, classes, and functions, along with rules for naming variables and using comments. Additionally, it highlights popular websites built with Python and offers guidance on running Python code and using its IDE.

Uploaded by

shweta1bgsws
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
You are on page 1/ 34

Welcome to the World of

Programming language - python


Introduction to Python
Contents
What is python?
History of python
Advantages of python
Application of Python
What can I do with python?
Why do people use python?
Popular website build with Python
Installing Python IDE
Running Python
Basic Datatypes
Variables , Objects and Classes
Rules for variables
Comments
Operators
What is Python?
Python is a popular high-level
programming language used in Interactive

various applications.
Python is an easy language to
Interpreted
learn because of its simple syntax
Python can be used for simple
tasks such as plotting or for more
complex tasks like machine Object Oriented
learning. Scripting Language

High Level Programming


Language
Beginner
It is Friendly
simple
Why
Mature
Versatile & Python Package
Libraries
Flexible
?
Support
Expandable AI
History of Python
Invented in the Netherlands, early 90s by Guido Van Rossum.
Python was conceived in the late 1980s and its implementation
was started in December 1989.
Guido Van Rossum is fan of ‘Monty Python’s Flying Circuis’
this is a famous TV show in Netherlands.
Named after Monty Python.
Open sourced from the beginning .
Advantages of Python

Free & Open Interpreted Vast Libraries


Source Language Support

Improved Dynamically Object


Productivity Typed Oriented
Advantages of Python Contd
Most programs on python require considerably less number
of lines of code to perform the same task compare to
another language like C. So less programming errors and
reduces the development time needed also.
Though Perl is a powerful language, it is highly syntax
oriented. Similarly C also.
Applications Of Python

Network Web & Internet


Programing 6 1 Development

Database Games and 3D


Access 5 2 Graphics

Business
Applications
4 3 Software
Development
Why do people use python?
The following primary factors cited by python users seem to be these:
Python is object-oriented
Structure supports such concepts as polymorphism operation
overloading & multiple inheritance
Its free (Open source)
Downloading and installing python is free and easy source code is
easily accessible.
It’s powerful
Dynamic typing
Build-in types & tools
library utility
Third party utility (e.g. Numeric, NumPy, SciPy)
Automatic memory management
It’s portable
Python runs virtually every major platform used today
As long as you have a compatible python interpreter installed, python programmes will
run in exactly the same manner, irrespective of platform.
Popular website build with Python
Reddit
YouTube Instagram

Google
Dropbox

Quora Pinterest
Installing Python IDE
Python is pre-installed on most Unix systems, including Linux and MAC OS X
But for in Windows operating systems , user can download from the
http://www.python.org/downloads/
- From the above link download the latest version of python IDE and install,
recent version is 3.4.1 but most of them uses version 2.7.7 only
Installing Python on Windows
Step: 1
❑ To download and install Python, go to Python's official
website http://www.python.org/downloads/
Step: 2
❑ When download is complete run .exe file to install
Python.
Step: 3
❑ You can see python installation.
Step: 4
❑ when installation was complete you can see message
“setup was successful” on screen.
IDLE Development Environment
❑ Integrated DeveLopment Environment

❑ Text editor with smart indenting for creating


python files.

❑ Menu commands for changing system settings


and running files.
How Python works
Interpreter

Byte Virtual
Compiler
Code Machine

Source code
Running
Code

Library
Module
Running Python
Once you are inside the Python interpreter, type in commands at will.
Examples:
>>> print ‘Hello world’
Hello world
Datatypes
Text Type: str

Numeric Types: int, float, complex

Sequence Types: list, tuple, range

Mapping Type: dict

Set Types: set, frozenset

Boolean Type: bool

Binary Types: bytes, bytearray, memoryview


Datatypes and Example
❑ When you assign a value to a variable data type is set :

int float str

a=10 a=2.5 a=“GKTCS”

complex list tuple

a = [ “python", a = ( “python",
a=2x “Java", “Html“ ] “Java", “Html“ )
dict set bool
a={
"name" : “Amit", a = { “python", a=True
“Java", “Html“ }
"age" : 25 }

complex bytes bytearray

a=2x a=b”GKTCS” a=bytearray(5)


Basic Datatypes
❑ Integers(for numbers)
a=4+3 #answer is 7, integer addition

❑ Floats
a=5/2 #answer is 2.5

❑ Strings
Can use “ ” or ‘ ’ to specify.
“GKTCS” or ‘GKTCS’ are same.
String Methods
title() upper() lower()

Converts the first Converts a string Converts a string


character of each into upper case into lower case
word to upper
case

isdigit() isupper() swapcase()

Returns True if all Returns True if all Swaps cases, lower


characters in the characters in the case becomes
string are digits string are in upper case and vice
upper case. versa
Variables, Objects, and Classes
A variable is a reference to a value stored in a computer’s memory.
Variables can be sorted into a variety of categories (or data types) such
as numbers (int/float etc), Boolean values (true/false), and
sequences (strings, lists etc).
An object is a collection of data from a computer’s memory that can be
manipulated.
ALL VARIABLES ARE OBJECTS although some objects can be defined by data referred to by multiple
variables.
Methods are the functions used to act on/alter an object’s data. They describe what your object can
“do.”
Variables, Objects, and Classes (cont.)
Instance #1
A class is a collection of objects who Color: Pink
Name: Polo
share the same set of
variables/methods. Instance #2
Color: Red
Name: Mini
The definition of the class provides a
blueprint for all the objects within it
Instance #3
(instances). Color: Blue
Name: Beetle
Instances may share the same variables
(color, size, shape, etc.), but they do
NOT share the same values for each
variable (blue/red/pink, small/large,
square/circular etc.)
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)
Function Syntax
def...: indicates that you are defining a new function.

function() refers to the name of your function. By convention, this name is typically lowercase and represents a verb/action.

a,b refers to parameters (values or variables) that can be used within the statements of your function’s definition (......). If your function has no parameters, an
empty parenthetical () is used.

The return statement is an optional statement that will return a value for your function to your original call.

def function(a, b):


......
return a + b
Comments
Comments can be used to improve readability of the
code.
1) Single-line comments
Simply create a line starting with the hash (#) character
#This would be a single line comment in Python

2) Multi-line comments
Created by adding a delimiter (""") on each end of the comment.

""" This would be a multiline comment in Python that


describes your code, your day, or anything you want it to """
Calling a function
Call the function by referring to its name (function()) and by placing
any necessary arguments (1, 2) within the parenthesis separated by
commas. myValue = function(1, 2)
If you wish, you can set your function call equal to a variable (myValue). The
value returned by the function will be assigned to your variable name.
myValue = function(1, 2)
Common Data Types and Operators
A data type is a means of classifying a value and determining what
operations can be performed on it. All objects have a data type.
Operators are symbols used carry out specific
functions/computations.
https://www.youtube.com/watch?v=v5MR5JnKcZI
Operators
Input/Output
Input functions (input()) allow users of a program to place values into programming code.

The parameter for an input function is called a prompt. This is a string (this can be indicated by “” or ‘’) such as “Enter a number: “
The user’s response to the prompt will be returned to the input statement call as a string. To use this value as any other data type, it must be
converted with another function (int()).

Print functions (print()) allow programs to output strings to users on a given interface.

The parameter of this function is of any type. All types will automatically be converted to strings.

xString = input(“Enter a number: “)


x = int(xString)
y=x+2
print(y)

You might also like