0% found this document useful (0 votes)
4 views

Lab 1 - SR

This document provides a comprehensive overview of Python programming, covering its features, data types, and key concepts such as identifiers, string slicing, and various data structures like lists, tuples, sets, and dictionaries. It also introduces essential operators, escape characters, and the NumPy library for array manipulation. The document serves as a revision guide for fundamental Python concepts and syntax.

Uploaded by

rocedo8037
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)
4 views

Lab 1 - SR

This document provides a comprehensive overview of Python programming, covering its features, data types, and key concepts such as identifiers, string slicing, and various data structures like lists, tuples, sets, and dictionaries. It also introduces essential operators, escape characters, and the NumPy library for array manipulation. The document serves as a revision guide for fundamental Python concepts and syntax.

Uploaded by

rocedo8037
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

Lab 1

Python Revision
Python is high level programming language.

Features of Python
• Simple and easy to learn
• Open source
• Support OOP
• Interpreted

Identifier
A Name in Python Program is called Identifier.
It can be Class Name OR Function Name OR Module Name OR Variable Name.
a=10

Rules to define Identifiers in Python:


1. The only allowed characters in Python are
• alphabet symbols (either lower case or upper case)
• digits (0 to 9)
• underscore symbol (_)
By mistake if we are using any other symbol like $ then we will get syntax error.

• ca$h =20 X
2. Identifier should not start with digit
• 123total X
3. Identifiers are case sensitive.
4. If identifier starts with (_) then it indicates it is private.
5. We cannot use reserved words as identifiers.

Data Types
1. Int
2. Float
3. Bool
4. Str
5. List
6. Tuple
7. Set
8. Dict
9. None

Python contains built-in functions:


1. Type(): check type of variable.
2. Id(): get address of object.
3. Print(): to print value.

String Slicing
1. Slice means a piece
2. [] operator is called slice operator, which can be used to retrieve parts of String.
3. In Python Strings follows zero based index.
4. The index can be either +ve or -ve.
• +ve index means forward direction from Left to Right
• -ve index means backward direction from Right to Left

List Data Type:


If we want to represent a group of values as a single entity where insertion order required to preserve, and
duplicates are allowed then we should go for list data type.
1) Insertion Order is preserved
2) Heterogeneous Objects are allowed
3) Duplicates are allowed
4) Growable in nature
5) Values should be enclosed within square brackets.
Tuple Data Type
Tuple data type is exactly same as list data type except that it is immutable.i.e we cannot change values.
Tuple elements can be represented within parenthesis.
Tuple is the read only version of list
Set Data Type
If we want to represent a group of values without duplicates where order is not important then we should
go for set Data Type.
1. Insertion order is not preserved.
2. Duplicates are not allowed
3. Heterogeneous objects are allowed.
4. Index concept is not applicable.
5. It is mutable collection
6. Growable in nature

dict Data Type:


If we want to represent a group of values as key-value pairs, then we should go for dict data type.
Eg: d = {101:'one',102:'two', 103:'three'}
Duplicate keys are not allowed but values can be duplicated. If we are trying to insert an entry with
duplicate key, then old value will be replaced with new value.

Escape Characters
The following are various important escape characters in Python
1. \n: New Line
2. \t: Horizontal Tab
3. \b: Back Space
4. \': Single Quote
5. \": Double Quote
6. \\: Back Slash Symbol

Arithmetic Operators
1. + → Addition
2. - → Subtraction
3. * → Multiplication
4. / → Division Operator
5. % → Modulo Operator
6. // → Floor Division Operator
7. ** → Exponent Operator OR Power Operator

Relational Operators
>, <, >=, <=

Equality Operators
==, !=

Logical Operators
And, or, not

NumPy
NumPy is a Python library used for working with arrays.
It also has functions for working in domain of linear algebra, fourier transform, and matrices.

Create NumPy ndarray Object


NumPy is used to work with arrays. The array object in NumPy is called ndarray.
We can create a NumPy ndarray object by using the array() function.

0-D Array
0-D arrays, or Scalars, are the elements in an array. Each value in an array is a 0-D array.

1-D Array
An array that has 0-D arrays as its elements is called uni-dimensional or 1-D array.
These are the most common and basic arrays.
2-D Array
An array that has 1-D arrays as its elements is called a 2-D array.
These are often used to represent matrix

Number of Dimensions

You might also like