01PY P-1 Introduction
01PY P-1 Introduction
Motivation
Programming isn't about what you know; it's about
what you can figure out
Problem solving
Programing
Coding, sometimes called computer programming,
is how we communicate with computers.
05 06 07
What is Python?
Python is a very popular general-purpose interpreted,
interactive, object-oriented, and high-level programming
language. Python is dynamically-typed and garbage-
collected programming language. It was created by
Guido van Rossum during 1985- 1990. Like Perl, Python
source code is also available under the GNU General
Public License (GPL).
Page 5
SCTIPT WAVE
Features of Python
Page 5
Script Wave
Environment set-up
In this course, we will be using Pycham as our code editor.
Steps for installation:
Page 5
Sript Wave
Working of python
Page 5
Script Wave
Commenting
Comments in Python are identified with a hash symbol, #, and
extend to the end of the line. Hash(#) characters in a string are
not considered comments, however. There are three ways to
write a comment - as a separate line, beside the corresponding
statement of code, or as a multi-line comment block.
Increasing readability
Explaining the code to others
Understanding the code easily after a long-term
Doc-strings
Re-using the existing code
Page 5
Script Wave
Code-Commenting
Page 5
Script Wave
Click file new file and new file window pops up.
Page 5
Sript Wave
First Output
Page 5
SCRIPT WAVE
Output-function
The print() function prints the specified message to the screen or another
standard output device.
The message can be a string, or any other object, the object will be converted
into a string before written to the screen.
print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False)
objects - object to the printed. * indicates that there may be more than one object
sep - objects are separated by sep. Default value: ' '
end - end is printed at last
file - must be an object with write(string) method. If omitted, sys.stdout will be used
which prints objects on the screen.
flush - If True, the stream is forcibly flushed. Default value: False
Page 5
Script Wave
Java Script
Variables PYTHON
Page 5
Script Wave
Page 5
Script Wave
Java Script
keyWords PYTHON
HTML5
Page 5
Script Wave
Quiz Time
From the following names mention which
are valid and invalid names
1. myvar = "John"
2. my_var = "John"
3. 2myvar = "John"
4. _my_var = "John"
5. myVar = "John"
6. my-var = "John"
7. MYVAR = "John"
8. continue = "John"
Script Wave
Quiz Time
From the following names mention which are valid and
invalid names
1. myvar = "John" Legal
2. my_var = "John" Legal
3. 2myvar = "John" Illegal
4. _my_var = "John" Legal
5. myVar = "John" Legal
6. my-var = "John" Illegal
7. MYVAR = "John" Legal
8. continue = "John" Illegal
Script Wave 2023
DATA
TYPES
Page 6
Coding School
DATA TYPES
Python Data Types are used to define the type of a
variable. It defines what type of data we are going to
store in a variable. The data stored in memory can be of
many types. For example, a person's age is stored as a
numeric value and his or her address is stored as
alphanumeric characters.
Note: In python we need not to declare any data types like
we do in C,C++,Java(int a=10;). we directly assign the value
when we need them
DATA TYPES Classification
Script Wave
2023
Data types
Page 6
Script Wave
Numeric
Number data types store numeric values. They are
immutable data types, which means that changing the
value of a number data type results in a newly allocated
object.
Numeric
Integer - Int
This value is represented by int class. It contains
positive or negative whole numbers (without
fraction or decimal). In Python there is no limit to
how long an integer value can be.
OUTPUT
CODE
Page 5
Script Wave
Float - float
This is a real number with floating-point representation.
It is specified by a decimal point.Optionally, the
character e or E followed by a positive or negative
integer may be appended to specify scientific notation.
OUTPUT
CODE
Scritp Wave
Complex - complex
A complex number is created from real numbers.
Python complex number can be created either using
direct assignment statement or by using complex ()
function.
OUTPUT
CODE
Script Wave
Strings
Strings in python are surrounded by either single
quotation marks, or double quotation marks.
Page 5
Script Wave
Strings
In Python, a string is a sequence of characters enclosed within single, double,
or triple quotes. Strings are one of the fundamental data types in Python and
are commonly used for text processing, manipulation, and storage.
Creating strings
You can create strings using single (' '), double (" "), or
triple (''' ''' or """ """) quotes. Examples:
Script Wave
Strings-Creationg code
Script Wave
Positive Indexing 0 1 2 3 4 5
P Y T H O N
Negative Indexing -6 -5 -4 3 -2 -1
Script Wave
Output:
Script Wave
String slicing
String slicing in Python is a fundamental operation that allows
you to extract a portion or substring from a string. It's a powerful
feature that's often used when working with text data.
Syntax:
substring = my_string[start_index:end_index:step]
OUTPUT
CODE 0 1 2 3 4 5
P Y T H O N
-6 -5 -4 3 -2 -1
Script Wave
Escape Sequence
Python Escape Sequence is a combination of
characters (usually prefixed with an escape
character), that has a non-literal character
interpretation such that, the character’s
sequences which are considered as an escape
sequence have a meaning other than the literal
characters contained therein.
Script Wave
Lists
Page 5
Script Wave
LISTS
Python Lists are just like dynamically sized arrays, declared in other
languages (vector in C++ and ArrayList in Java). In simple language, a
list is a collection of things, enclosed in [ ] and separated by commas.
Sort()
Script Wave
MATHS ON LIST
Addition [Concatenation] Multiplication
Script Wave
TUPLE
Python Tuple is a collection of
objects separated by commas. In
some ways, a tuple is similar to a
Python list in terms of indexing,
nested objects, and repetition but
the main difference between both is
Python tuple is immutable, unlike
the Python list which is mutable.
Script Wave
COUNT
Script Wave
sum()
Script Wave
LIST TUPLE
Unexpected changes and errors are Because tuples don’t change they
more likely to occur are far less error-prone.
Script Wave
SET OPERATIONS
A set is a collection of unique
elements without any specific
order.
Script Wave
DICT ACCESSING
A dictionary in Python is an unordered
collection of items. Each item in a
dictionary is a key-value pair.
DICT OPERATIONS
Create Update
Read Delete
Script Wave
OPERATORS 2023
Operators
Page 6
Script Wave 2023
Operators!
Script Wave
ARITHEMATIC OPERATORS
Operator Description Syntax
ASSIGNMENT OPERATORS
Operator Description Syntax
Add and Assign: Add right side operand with left side operand and then assign
+= a += b
to left operand
Subtract AND: Subtract right operand from left operand and then assign to left
-= a -= b
operand: True if both operands are equal
Multiply AND: Multiply right operand with left operand and then assign to left
*= a *= b
operand
Divide AND: Divide left operand with right operand and then assign to left
/= a /= b
operand
Modulus AND: Takes modulus using left and right operands and assign result
%= a %= b
to left operand
Script Wave
COMPARISION OPERATORS
== Equal x == y
!= Not equal x != y
LOGICAL OPERATORS
and Returns True if both the operands are true x and y x>7 and x>10