KEMBAR78
Lecture 1-2 | PDF | Python (Programming Language) | Variable (Computer Science)
0% found this document useful (0 votes)
7 views6 pages

Lecture 1-2

Python is a high-level, interpreted programming language created by Guido Van Rossum, known for its simplicity and versatility in application development. It supports Object Oriented Programming, has a large standard library, and is open source, making it suitable for various applications including web and desktop GUI development. Python features easy-to-learn syntax, automatic memory management, and a dynamic typing system, along with specific naming conventions for variables and constants.

Uploaded by

jeenamukesh33
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)
7 views6 pages

Lecture 1-2

Python is a high-level, interpreted programming language created by Guido Van Rossum, known for its simplicity and versatility in application development. It supports Object Oriented Programming, has a large standard library, and is open source, making it suitable for various applications including web and desktop GUI development. Python features easy-to-learn syntax, automatic memory management, and a dynamic typing system, along with specific naming conventions for variables and constants.

Uploaded by

jeenamukesh33
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/ 6

Python Introduction

Python is a general-purpose, high-level, dynamic, and interpreted programming language. It


also supports Object Oriented Programming (OOP) approach to develop applications.

Python is created by Guido Van Rossum between 1985-1990.

Python is a simple, easy to learn yet powerful and versatile scripting language, which makes
it an attractive language for Application Development.

Python has very fast development and debugging because there is no compilation step
required and the edit-test-debug cycle is very fast.

It is an open source language, which is issued under the GPL-compliant license.

Python Features
The Python programming language provides lots of features, which are listed as follows:

1. Easy to Learn: It is very easy to learn and use because of its simple and developer-
friendly syntax.

2. Expressive Language: It is an expressive language means that it is easily understandable


and readable.

3. Interpreted Language: It is an interpreted-based language that allows the execution of


code line by line at a time.

4. Cross Platform: It is a portable and platform-independent language as it can run on almost


any platform, including Windows, Linux, Mac, Unix etc.

5. Free and Open Source: It is open source and freely available at https://www.python.org.

6. Object Oriented: It is an Object Oriented Programming language, which makes it more


applicable in real-world applications.

7. Large Standard Library: It has a large standard library which provides rich set of
functions and modules that can be used directly in our code.

8. Integrated: It can be easily integrated with low languages such as C, C++, Java etc.

9. GUI Programming: It supports GUI applications that can be created and ported.

10. Databases: It provides interface to all major commercial databases.

11. Automatic Memory Management: It supports automatic memory management which


means the memory is cleared and freed automatically.
Python Applications
Python can be applied in various application areas, which are as follows:

1. Web Applications: It is used to develop scalable and secure web applications. It provides
a wide range of libraries to handle internet protocols and also provides Frameworks such as
Django, Pyramid, Flask etc to develop and deploy various simple as well as complex web-
based applications.

2. Desktop GUI Applications: It can be used to develop GUI as well. Tk is an open-source


widget toolkit that can be used to develop Python-based desktop applications. Some other
useful toolkits are wxWidgets, Kivy, pyqt etc.

3. Software Development: It is very helpful in software development process.

Python Comments
Comment in Python is the hidden code that is not interpreted by the interpreter and used to
explain the program code.

Although comments are not a necessary part of a program but it improve the readability of
our program and make the program more easily understandable to everyone.

Like many other programming languages, Python also supports 2 types of comments, which
are as follows:

1. Single line comment

It is used to comment on only a single line of code in our program. The # (hash) is used for a
single-line comment.

Example

#This is a single line comment

2. Multi-line comment

It is used to comment multiple lines of code in our program. A multiple-line comment is


enclosed in triple quotes (""" """).

Example

""" This is
a multiline comment
"""
Python Variables
A Python variable is a named location used to store data in memory. Each variable should
have a specific name that is called identifier.

In Python, the declaration is not required to reserve memory space for the variable. The
“variable declaration” or “variable initialisation” occurs when we assign values to a variable.

A Python constant is a type of variable whose value cannot be changed. It can be considered
as containers that hold information which can’t be changed later.

Python is a case-sensitive language means GautamKumar and Gautamkumar are two


different variables.

It is recommended to use lowercase letters for variable names and uppercase letters for
constant names.

Naming Conventions
The naming conventions for variables and constants in Python are as follows:

1. First character of the variable must be either an alphabet or an underscore ( _ ), but it


cannot be a digit (0-9).
2. All characters except the first character can be an alphabet, underscore or a digit.
3. Variable name should NOT contain any white-space or special character (!, @, #, %,
^, &, *).
4. Variable name must be different from the reserved keywords.
5. Variable names are case sensitive means Abc and abc are different.
6. Constants are put into Python modules and meant not be changed.

Examples of valid variable names:

ab21, _td, t_38, tuto65Kumar, etc

Examples of Invalid variable names:

1abc, td%8, ab cd, abc@12, etc.

Python is a dynamically typed language means we are not bound to declare a variable before
using that instead, it allows us to create a variable at the required time.

The equal (=) operator is used to assign a value to a variable. The name of the variable will
always be on the left side, and its value will be on the right side.
Example:

a = 17 #stores integer
b = 195.23 #stores floating point
c = "Gautam" #stores string

Python allows us to assign a single value to multiple variables in a single statement.


Example:

a=b=c = 135
print (a) #prints 135
print (b) #prints 135
print (c) #prints 135

Python allows us to assign multiple values to multiple variables in a single statement.


Example:

a,b,c = 70,80,90
print (a) #prints 70
print (b) #prints 80
print (c) #prints 90

Python Keywords
Keywords in Python are the reserved words that have a special meaning for the interpreter
and perform a specific operation. During coding, keywords can’t be used as variable names
or any other identifiers. They are used to define Python language syntax and structure.

Keywords are case sensitive in Python language.

The list of keywords in Python is as follows:

False True Class finally return


Is None continue for lambda
Try def From while nonlocal
And Del global not with
As Elif if or yield
assert Import else pass
break Except in raise
Python Literals
A Python literal is a source code representation of a fixed value. It can be assigned to any
primitive type variable.

Python supports the following types of literals,

1. Numeric literals
A numeric literal can be created by providing a numeric value.
Example

num1 = 121
num3 = 147.92
num4 = 8+3j

2. String literals
A string literal can be created by enclosing a sequence of characters in either single or double
quotes.
Example
#Single line string
str1 = "Gautam Kumar"

#Multiple line string


str2 = "Gautam\ #Using backslash at the end of each line
Kumar"
str3 = """Gautam #Using triple quotation marks
Kumar"""

3. Boolean literals
A boolean literal can be created using either True or False.

Example
bool1 = True
bool2 = False

4. Special Literals

In Python, we have a special literal i.e., None, which is used to specify a field that is not
created. It is also used at the end of lists.

Also, none is stored when we try to store the return value of a function that does not return
any value.

Example
def myFunction(): # function that does not return any value
fn = 12
x = myFunction() # stores ‘None’ in x
print(x) # prints ‘None’

5. Literal Collections

Literal collections in python are the collections of Lists, Tuples, and dictionaries.

Example

list1 = ["Gautam", 123, 17.4, "Kumar"]


tuple1 = ("Gautam", 123, 17.4, "Kumar")
dict = {1: "Gautam", "two": "Kumar"}

You might also like