0% found this document useful (0 votes)
148 views28 pages

Python Introduction

Python is a general-purpose programming language that can be used for a wide variety of tasks. It supports object-oriented programming and provides high-level data structures. Python code is highly readable and it can interface with many different systems.

Uploaded by

vickyverma
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
Download as pptx, pdf, or txt
0% found this document useful (0 votes)
148 views28 pages

Python Introduction

Python is a general-purpose programming language that can be used for a wide variety of tasks. It supports object-oriented programming and provides high-level data structures. Python code is highly readable and it can interface with many different systems.

Uploaded by

vickyverma
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1/ 28

python

Python is a general-purpose interpreted, interactive, object-oriented, and high-level


programming language. It was created by Guido van Rossum during 1985- 1990.
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
What can Python do?

1. Python can be used on a server to create web applications.

2. Python can be used alongside software to create workflows.

3. Python can connect to database systems. It can also read and modify files.

4. Python can be used to handle big data and perform complex mathematics.

5. 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-orientated way
or a functional way
Python Syntax compared to other
programming languages

•Python was designed for readability, and has some similarities to the English

language with influence from mathematics.

•Python uses new lines to complete a command, as opposed to other programming

languages which often use semicolons or parentheses.

•Python relies on indentation, using whitespace, to define scope; such as the scope

of loops, functions and classes. Other programming languages often use curly-

brackets for this purpose.


Python Features
1) Easy to Learn and Use
Python is easy to learn and use. It is developer-friendly and high level programming
language.

2) Expressive Language
Python language is more expressive means that it is more understandable and readable.

3) Interpreted Language
Python is an interpreted language i.e. interpreter executes the code line by line at a time.
This makes debugging easy and thus suitable for beginners.

4) Cross-platform Language
Python can run equally on different platforms such as Windows, Linux, Unix and
Macintosh etc. So, we can say that Python is a portable language.
5) Free and Open Source
offical web address.The
Python language is freely available at

source-code is also available. Therefore it is open


source.

6) Object-Oriented Language
Python supports object oriented language and concepts of classes and objects come into
existence.

7) Extensible
It implies that other languages such as C/C++ can be used to compile the code
and thus it can be used further in our python code.
8) Large Standard Library
Python has a large and broad library and provides rich set of module
and functions for rapid application development.

9) GUI Programming Support


Graphical user interfaces can be developed using Python
Creating Python Project in PyCharm
Give a meaningful project name.
Writing and running your first Python Program
How to display output
Output using the print()
function
To output your data to the screen, use the print() function. You can write
print(argument) and this will print the argument in the next line when
you press the ENTER key.
More on using print():

Syntax:
print (value,……….,value N,sep=‘ ‘,end=‘ ‘)
Example: Output Description
print(10,20,30) 10 20 30 Space is the default separator
print(10,20,30,sep=“*”) 10*20*30 * As separator
print(10,20,30,sep=“-*-”) 10-*-20-*-30 -*- as separator
print(10,20,30,sep=“,”) 10,20,30 , as separator
print(10,20,30,sep=“\n”) 10 \n(new line character) as separator
20
30
What is the use of end=‘ ‘ in print() function?

Example:
print( 10 , 20 , 30 , sep=“,” , end=“!!!!\n” )

Output:

10 , 20 , 30 !!!!
print "hello" * 5 hellohellohellohellohello

print(2*"world") worldworld

print(10**3) 1000

print(10*3) 30
Tokens Of pythons
It is the smallest element of a python program that is
meaningful to the compiler. The programmer can write a
program by using tokens.

Identifiers Keywords Literals Operators


Identifiers
An identifier is a sequence of letters and digits.The term identifiers
are used to describe the name of constants, variables, functions
etc.

•The first character of the variable must be an alphabet or underscore ( _ ).


•All the characters except the first character may be an alphabet of lower-case(a-z), upper-
case (A-Z), underscore or digit (0-9).
•Identifier name must not contain any white-space, or special character (!, @, #, %, ^, &, ).
•Identifier name must not be similar to any keyword defined in the language.
•Identifier names are case sensitive for example my name, and MyName is not the same.
•Examples of valid identifiers : a123, _n, n_9, etc.
•Examples of invalid identifiers: 1a, n%4, n 9, etc.
Python Keywords
Python Keywords are special reserved words which convey a special meaning to the
compiler/interpreter. Each keyword have a special meaning and a specific operation.
These keywords can't be used as variable. Following is the List of Python Keywords.
Python Literals
Literals or constants are those tokens whose value do not change during the
program execution.

Types of python literals are:

1. String literals:

String literals can be formed by enclosing a text in the quotes. We can


use both single as well as double quotes for a String.
Eg:
"Aman" , '12345‘ , “ABC123”

There are two types of Strings supported in Python:


a).Single line String- Strings that are terminated within a single line are known as
Single line Strings.
Eg:
>>>'hello'
b).Multi line String- A piece of text that is spread along multiple lines is
known as Multiple line String.

Using triple quotation marks:-


Eg:
>>> ”””welcome
to
SSSIT”””
Numeric literals

(integers)
Numbers( can be both
positive and negative) with
no fractional part.eg: 100

(floating point)

Real numbers with both


integer and fractional part
eg: -26.2
Python Data Types
The data type of a value (or variable in some contexts) is an attribute that tells what
kind of data that value can have. Data types define particular characteristics of data
used in software programs and inform the compilers about predefined attributes
required by specific variables or associated data objects. Data types include the
storage classifications like integers, floating point values, strings, characters etc.

Python provides various standard data types that define the storage method on
each of them. The data types defined in Python are given below.
1. Numbers
2. String
3. List
4. Tuple
5. Dictionary
Numbers
Number stores numeric values. Python creates Number objects
when a number is assigned to a variable.

For example;
a = 3 , b = 5 #a and b are number objects

Python supports 4 types of numeric data.


int (signed integers like 10, 2, 29, etc.)
long (long integers used for a higher range of values like
908090800L, -0x1929292L, etc.)
float (float is used to store floating point numbers like 1.9, 9.902,
15.2, etc.)
complex (complex numbers like 2.14j, 2.0 + 2.3j, etc.)
String
The string can be defined as the sequence of characters
represented in the quotation marks. In python, we can use
single, double, or triple quotes to define a string.

The following example illustrates the string handling in


python.
str1 = 'hello javatpoint' #string str1
str2 = ' how are you' #string str2
Python Variables

Variables are nothing but reserved memory locations to store values. This means that
when you create a variable you reserve some space in memory.
Based on the data type of a variable, the interpreter allocates memory and decides
what can be stored in the reserved memory.

Declaring Variable and Assigning Values

The equal (=) operator is used to assign value to a variable.

Example:
x=10
y=20
Example: Multiple Assignments
x=y=z=10
Or
x,y,z=10,20.5,”ABC”
Python Data Types

Built-in 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
Sequence Types: list, tuple, range
Mapping Type: dict
Set Types: set, frozenset
Boolean Type: bool
Binary Types: bytes, bytearray, memoryview
Getting the Data Type

You can get the data type of any object by using the type() function:

x=5
print(type(x))
Type Conversion

You can convert from one type to another with the int(), float(), and complex()
methods

Python Casting

There may be times when you want to specify a type on to a variable. This can be
done with casting. Python is an object-orientated language, and as such it uses
classes to define data types, including its primitive types.

Casting in python is therefore done using constructor functions:

int() - constructs an integer number from an integer literal, a float literal (by
rounding down to the previous whole number), or a string literal (providing the
string represents a whole number)
float() - constructs a float number from an integer literal, a float literal or a string
literal (providing the string represents a float or an integer)
str() - constructs a string from a wide variety of data types, including strings,
integer literals and float literals
How to accept the value from user in python
Python has an input function which lets you ask a user for some text input.
You call this function to tell the program to stop and wait for the user to key
in the data. By default input function provide value in string.

input() Function

If the input function is called, the program flow will be stopped until
the user has given an input and has ended the input with the return
key. The input of the user will be interpreted. If the user e.g. puts in an
integer value, the input function returns this integer value.

You might also like