0% found this document useful (0 votes)
20 views14 pages

Introduction to Python Programming

Python is a versatile programming language created by Guido van Rossum in 1991, used for web applications, data handling, and software development. It features a simple syntax that enhances readability and allows for rapid prototyping. Python supports various programming paradigms and is available for free download from its official website.

Uploaded by

yashfeensania360
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)
20 views14 pages

Introduction to Python Programming

Python is a versatile programming language created by Guido van Rossum in 1991, used for web applications, data handling, and software development. It features a simple syntax that enhances readability and allows for rapid prototyping. Python supports various programming paradigms and is available for free download from its official website.

Uploaded by

yashfeensania360
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

What is Python?

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


Rossum, and released in 1991.

It is used for:

1|Page
What can Python do?

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


Python can be used alongside software to create workflows.
Python can connect to database systems. It can also read and
modify files.
Python can be used to handle big data and perform complex
mathematics.
Python can be used for rapid prototyping, or for production-
ready software development.

2|Page
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-oriented
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.

Installation:

3|Page
You can download it for free from the following website:
[Link]

Python Getting Started:

Syntax:

The writing of the python code depends on the indentation. Indentation


refers to the spaces at the beginning of a code line.

Where in other programming languages the indentation in code is for


readability only, the indentation in Python is very important.

Python uses indentation to indicate a block of code.

4|Page
Comments:

Comments can be used to explain Python code.


Comments can be used to make the code more readable.
Comments can be used to prevent execution when testing code.

Creating a Comment:
There are two ways to comment :
One-line comment
Multi-line comment
One-line comment starts with a # and Python will ignore them.
Multi-line comment starts with three-single quotes (‘’’) and ends with
three-single qoutes (‘’’).

5|Page
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.

Variables do not need to be declared with any particular type, and can
even change type after they have been set.

6|Page
Get the Type:

You can get the data type of a variable with the type() function.

Variable names are case-sensitive.

Defining Variable Names:

7|Page
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)
A variable name cannot be any of the Python keywords.

Assign Multiple Values:

Many Values to Multiple Variables


Python allows you to assign values to multiple variables in one line.

One Value to Multiple Variables


And you can assign the same value to multiple variables in one line.

8|Page
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:

9|Page
Numbers
There are three numeric types in Python:
int
float
complex
Variables of numeric types are created when you assign a value to them:

x = 1 # int
y = 2.8 # float
z = 1j # complex

Type Casting:
There may be times when you want to specify a type on to a variable.
This can be done with casting.

Casting in python is therefore done using constructor functions:

int() - constructs an integer number from an integer literal, a


float literal (by removing all decimals), 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.

10 | P a g e
Strings:

Strings in python are surrounded by either single quotation marks, or


double quotation marks.

'hello' is the same as "hello".

String Length:

To get the length of a string, use the len() function.

11 | P a g e
Check String:

To check if a certain phrase or character is present in a string, we can


use the keyword in.

Slicing Strings:

You can return a range of characters by using the slice syntax.

Specify the start index and the end index, separated by a colon, to
return a part of the string.

12 | P a g e
Modify Strings

Python has a set of built-in methods that you can use on strings.

13 | P a g e
String Concatenation:

To concatenate, or combine, two strings you can use the + operator.

String Formatting:

The format() method takes the passed arguments, formats them, and
places them in the string where the placeholders {} are:

14 | P a g e

You might also like