What Is Python
What Is Python
ABOUT PYTHON
Python is a popular programming language.
Created by Guido Van Rossum, and released
in 1991.
Used for :-
Web development (server-side),
Software development,
Mathematics
System scripting.
APPLICATIONS OF PYTHON
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.
CONTD…
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.
FEATURES OF PYTHON
PROGRAMMING LANGUAGE
Simple
Easy to Learn
Free and Open source
High Level Language
Interpreted
Portable
Object Oriented
Extensible
Embeddable
Extensive Libraries
Designed for readability, and has some similarities
to the English language with influence from
COMPARISON OF PYTHON WITH OTHER PROGRAMMING LANGUAGES
mathematics.
Syntax errors
Runtime errors
SYNTAX ERROR
Syntax errors are like grammatical errors in
English. They occur when the defined rules are
not followed.
For example:
prin("Hello World")
The Python interpreter generates the following
syntax error as it did not find a name prin (as
the correct method name is print).
RUNTIME ERROR
Occur due to incorrect algorithm/logic or
wrong operations like dividing by zero during
the program execution.
EXAMPLE OF RUNTIME ERROR
EXAMPLE
Write a Program to Print:-
Python is Easy
Solution:-
print(“Python is Easy”)
Interesting ways to use
Print functions
1ST: WITH COMMA AS A
SEPARATOR
2ND: WITH SPACE AS A
SEPARATOR
3RD: WITH REPEAT CHARACTER
We can print a string n times by using repeat
character (*) as shown below:
EXAMPLE:
TYPES OF COMMENTS IN
PYTHON
1) Single-line Comment
2) Docstring Comment
SINGLELINE COMMENT
It starts with # (hash) and the content
following hash till the end of that line is a
comment
DOCSTRING COMMENT
Python has a way to specify documentation
comments known as docstrings.
A docstring is a simple text usually in English,
placed in your code to explain what a
specific part of code does.
A docstring is a text enclosed in triple
quotes, and it’s usually the first non-
comment statement in a module, function,
class or method definition.
This docstring becomes a special attribute
called __doc__ for that object.
Python allows both triple double quote “””
and triple single quote’’’ to create docstring.
The main purpose of docstring in python is
to provide information on what a particular
python does and not how It does.
Docstring always begin with capital letter
and end with a period(.).
There are two types of docstring:
“””
This is a multiline comment.
And I am printing hello world”””
print(“Hello World”)
IDENTIFIER
An Identifier is a name used to identify a
variable, function, class, module or object.
Valid identifiers:
var1
_var1
_1_var
var_1
Invalid Identifiers
!var1
1var
1_var
var#1
var 1
PYTHON KEYWORDS
Python has a set of keywords that are
reserved words that cannot be used as
variable names, function names, or any
other identifiers.
Python 3.5 has 33 keywords.
Python 3.7 has 35 keywords.
Keyword Description
as To create an alias
finally Used with exceptions, a block of code that will be executed no matter if there is an exception or not
or A logical operator
Example:
number1 = number2 = number3 = 100
print(type(x))
print(type(y))
print(type(z))
ADD A VARIABLE TO ANOTHER
x = "Python "
y = "is "
z = "awesome"
print(x + y + z)
OUTPUT BOTH TEXT AND
VARIABLES
x = "Python"
y = "is"
z = "awesome"
print(x, y, z)
TYPE CONVERSION
CASTING INTEGER
x = int(1)
y = int(2.8)
z = int("3")
print(x)
print(y)
print(z)
CASTING FLOAT
x = float(1)
y = float(2.8)
z = float("3")
w = float("4.2")
print(x)
print(y)
print(z)
print(w)
CASTING STRING
x = str("s1")
y = str(2)
z = str(3.0)
print(x)
print(y)
print(z)