SlideShare a Scribd company logo
ASHA NIVEDITHA
SOFTWARE TECHNICAL TRAINER
INTRODUCTION TO PYTHON
PROGRAMMING
LANGUAGE
•A programming language is a type of
written language that tells computers
what to do.
•A "program" in general, is a sequence
of instructions written so that a
computer can perform certain task.
NEED OF
PROGRAMMING
LANGUAGE
Types of programming languages
The programming languages are broadly classified into three types,
• Low-level language
• High-level language
• Middle-level language
Low-level langu
age
It is machine-dependent.
It works based on the binary number
0’s and 1’s.
The processor runs low-level programs
directly without the need of a compiler
or interpreter so the program written in
low-level language can be run very fast.
High-level programming language
High-level programming language (HLL) is designed for developing
user-friendly software programs and websites.
This programming language requires a compiler or interpreter to
translate the program into machine language (execute the program).
Example: Python, Java, JavaScript, PHP, C#, C++, etc.
Middle-level programming language
Middle-level programming language lies between the low-level programming language and the
high-level programming language.
It is also known as the intermediate programming language and pseudo-language.
A middle-level programming language's advantages are that it supports the features of
high-level programming, it is a user-friendly language, and is closely related to machine
language and human language.
Example: C, C++, language
PYTHON
Interpreted programming language
Dynamic
Object Oriented
Versatile scripting language
Multiple programming paradigms.
PROGRAMMING
VS
SCRIPTING
Scripts are few lines of code used
within a program. These scripts
are written to automate some
particular tasks within the
program.
Programming languages are a set
of code/instructions for the
computer that are compiled at
runtime. Thus an exe file is
created
Advantages and Disadvantages of Python
HISTORY
Python was created by Guido van Rossum,
and first released on February 20, 1991.
While you may know the python as a large
snake, the name of the Python
programming language comes from an old
BBC television comedy sketch series called
Monty Python's Flying Circus.
PART - 1  Python Introduction- Variables- Data types - Numeric- String- Boolean.pptx.pdf
PART - 1  Python Introduction- Variables- Data types - Numeric- String- Boolean.pptx.pdf
FEATURES
Easy to read and learn
Free and Open source
Cross platform
Large standard library
Extensible
GUI Programming support
APPLICATIONS
Web applications
GUI based desktop
applications(Games,
Scientific
Applications)
Operating Systems
Enterprise and
Business
applications
Audio or video
based applications
3D CAD application
SCOPE OF PYTHON
DOWNLOADING AND INSTALLATION
Visit the link https://www.python.org
Ways to run Python Scripts
1. Command Line [python script.py]
✔ Open a terminal or command prompt.
✔ Navigate to the directory containing your Python script using the cd command.
2. IDLE (Python's Integrated Development and Learning Environment):
✔ Open IDLE and use the "File" menu to open your script, then run it.
3. Jupyter Notebooks [Using interpreter interactively]
✔ If you are using Jupyter Notebooks, you can run individual cells or the entire notebook.
✔ Use the "Run" button or press Shift + Enter to execute a cell.
IDE
An integrated development
environment (IDE) is a
software application that
helps programmers develop
software code efficiently. It
increases developer
productivity by combining
capabilities such as software
editing, building, testing, and
packaging in an easy-to-use
application.
ANACONDA PYTHON
Anaconda is a distribution of the Python
and R programming languages for
scientific computing (data science,
machine learning applications,
large-scale data processing, predictive
analytics, etc.), that aims to simplify
package management and
deployment.
PART - 1  Python Introduction- Variables- Data types - Numeric- String- Boolean.pptx.pdf
PART - 1  Python Introduction- Variables- Data types - Numeric- String- Boolean.pptx.pdf
VARIABLE
• In Python, variables are a storage placeholder for texts and numbers.
• It must have a name so that you are able to find it again
• The variable is always assigned with the equal sign, followed by the value of the variable.
• A variable is created the moment we first assign a value to it.
Example:
a=10
b=“IBM”
print(a)
Print(b)
RULES FOR CREATING VARIABLES
Must start with a letter or the underscore character
Cannot start with a number
Can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )
Case-sensitive (name, Name and NAME are three different variables)
The reserved words(keywords) cannot be used naming the variable
Assigning a
single value
to multiple
variables
Example::
x=y=z= 100
print(x)
print(y)
print(z)
Assigning
different values
to multiple
variables
Example:
x, y, z =10, 20.20, “IBM CE”
print(x)
print(y)
print(z)
Can we use
same name
for different
types?
If we use same name, the variable
starts referring to new value and type.
Example:
x=23
x=“salary”
print(x)
How does +
operator work
with variables
Example:
x = 100
y = 200
print(x + y)
x = "IBM"
y = "CE"
print(x + y)
Can we use + for different
types also?
‘+’ used for adding different data types will produce an error.
Example:
age= 10
name = "David"
print(age+name)
OUTPUT: TypeError: unsupported operand type(s) for +: 'int'
and 'str'
Keywords
•Keywords are special reserved words
which convey a special meaning to the
compiler/interpreter.
•Each keyword have a special meaning
and a specific operation.
import keyword
print(keyword.kwlist)
PART - 1  Python Introduction- Variables- Data types - Numeric- String- Boolean.pptx.pdf
IO OPERATIONS
•print( ) - Used for output operation
•input( ) - Used for input operations.
name = input()
number = int(input())
print ('my name is:’, name, 'and my age is:',
number)
Data types
DATA TYPES
Immutable Data Types
Numeric types(int, float, complex)
Tuple
String and Boolean
Mutable Data Types
List
Dictionary
Set
Data Types:-
Variables will hold values, and every value has its own
data-type.
Python is a dynamically typed language
Hence we do not need to define the type of the variable
while declaring it.
The interpreter implicitly binds the value with its type.
a = 5
The variable a holds integer value five and we did not define
its type. Python interpreter will automatically interpret
variables a as an integer type.
Python enables us to check the type of the variable used in the
program. Python provides us the type() function, which
returns the type of the variable passed.
Numeric Datatype :-
Numeric values are known as numbers.
There are three types.
integer, float, and complex
(They may be +ve /-ve)
Python provides the type() function to know the data-type
of the variable.
Example: Output:
x=1 #integer <Class ‘int’>
y=13.6 #float <Class ‘float’>
z=6+1j #complex <Class ‘complex’>
print(type(x))
print(type(y))
print(type(z))
Comments
Helps explaining Python code.
make the code more readable.
prevent execution when testing code.
Comments starts with a #, and Python will ignore them
Constants
A constant is a special type of variable whose value cannot
be changed.
import constant
print(constant.PI) # prints 3.14
print(constant.GRAVITY) # prints 9.8
Type Conversion:-
#convert from int to float:
x = 1
a = float(x)
print(a)
#convert from float to int:
y = 2.8
b = int(y)
print(b)
#convert from int to complex:
z = 1
c = complex(z)
print(c)
Points to Remember:-
All the keywords must be used as they have defined.
(Uppercase and Lower Case)
Keywords should not be used as identifiers like variable names,
functions name, class name, etc.
The meaning of each keyword is fixed, we can not modify or
remove it.
Booleans
Booleans represent one of two values: True or False.
Input: Output:
print(10 > 9) True
print(10 == 9) False
Strings
String is a sequence of characters.
String may contain alphabets, numbers and special characters.
Usually strings are enclosed within a single quotes and double
quotes.
Example: a= “hello world‟ b= ‘Python’
We can display a string literal with the
print() function.
Example 1:
String1 ="I'm a technical lead"
print(String1)
Example 2 :
String2 ='I'm a technical lead’
print(String2)
Example 3:
String3 ='''I'm a technical lead and “tester”"'
print(String3)
Example 4:
String4 =‘‘‘python
for
datascience ”’
print(String4)
OUTPUT for Example 1:
I'm a technical lead
OUTPUT for Example 2:
SyntaxError: invalid syntax
OUTPUT for Example 3:
I'm a technical lead and "tester"
OUTPUT for Example 4:
python
for
datascience
Multiline Strings
We can assign a multiline string to a variable by using three quotes.
a = ""“You get
What you work for
Not what you
wish for."""
print(a)
Strings in Python are arrays of bytes representing unicode characters.
Python does not have a character data type, a single character is simply a
string with a length of 1.
Square brackets can be used to access elements of the string.
Indexing:-
a = "Hello, World!"
print(a[1])
Accessing characters in Python
Individual characters of a String can be accessed by using
the method of Indexing.
To access a range of characters in the String, method of
slicing is used.( done by using a Slicing operator (colon)).
Strings indexing and splitting
The indexing of the python strings starts from 0.
b = "Hello, World!"
print(b[3:-5])
Slicing:-
b = "Hello,World!"
print(b[2:5])
b = "Hello,World!"
print(b[:5])
b = "Hello,World!"
print(b[2:])
Output:
b="hello,world!"
print(b)
print(b[2:5])
print(b[2:])
print(b[:5])
print(b[3:-5])
hello,world!
llo
llo,world!
hello
lo,w
Deleting/Updating from a String
Updation or deletion of characters from a String is not allowed.
This will cause an error because item assignment or item
deletion from a String is not supported.
Although deletion of entire String is possible with the use of a
built-in del keyword.
This is because Strings are immutable, hence elements of a
String cannot be changed once it has been assigned.
Only new strings can be reassigned to the same name.
Deleting Entire String:(using del keyword)
Example:
String1 = "Hello, I'm john"
print(String1)
# Deleting entire String
del String1
print("nDeleting the entire string ")
print(String1)
OUTPUT:
Hello, I'm john
Deleting the entire string
NameError: name 'String1' is not defined
Find the output
str1="IBM"
print(str1[5])
print(str1)
OUTPUT:
IndexError: string index out of range
IBM
NOTE
✔ While accessing an index out of the range will cause an Index
Error.
✔ Only Integers are allowed to be passed as an index, float or
other types will cause a TypeError.
String operations
Concatenation of Two or More Strings
Removes any whitespace from the beginning or the end
The length of a string
Strings in lower case
Strings in upper case
Replaces a string with another string
Splits the string into substrings
Concatenation of Two or More Strings
Joining of two or more strings into a single one is called
concatenation.
Example:
str1 = "python"
str2 ="programming"
# using +
print("str1 + str2 = ", str1 + str2)
OUTPUT:
str1 + str2 = pythonprogramming
Example:
str1 = "python"
# using *
print('str1 * 3 =', str1 * 3)
OUTPUT:
str1 * 3 = pythonpythonpython
Removes any whitespace from the beginning or the
end
Example:
A = “ Hello, World! ”
print(A)
a = " Hello, World! “
print(a.strip())
OUTPUT:
Hello, World!
Hello, World!
To find the the length of a string
Example:
a = "Hello, World!"
print(len(a))
OUTPUT:
13
Strings in lower case
Example:
a = "HELLO, World!"
print(a.lower())
OUTPUT:
hello, world!
Strings in upper case
Example:
a = "Hello, World!"
print(a.upper())
OUTPUT:
HELLO, WORLD!
Replaces a string with another string
Example:
a = "Hello, World!"
print(a.replace("H", “F"))
OUTPUT:
Fello, World!
Splits the string into substrings
Example:
a = "Hello, World!"
print(a.split(","))
OUTPUT:
['Hello', ' World!']
String Methods In Python:-
String Methods In Python:-
String Methods In Python:-
String Methods In Python:-

More Related Content

Similar to PART - 1 Python Introduction- Variables- Data types - Numeric- String- Boolean.pptx.pdf (20)

PDF
Python Programming
Saravanan T.M
 
PPTX
INTRODUCTION TO PYTHON.pptx
Nimrahafzal1
 
PPTX
Python basics
ssuser4e32df
 
PPTX
Chapter 1-Introduction and syntax of python programming.pptx
atharvdeshpande20
 
PPT
Python - Module 1.ppt
jaba kumar
 
PPTX
Fundamentals of Python Programming
Kamal Acharya
 
PPTX
UNIT 1 .pptx
Prachi Gawande
 
PPTX
Python Programming 1.pptx
Francis Densil Raj
 
PPTX
Chapter1 python introduction syntax general
ssuser77162c
 
PPTX
Introduction to Python Programming .pptx
NaynaSagarDahatonde
 
PPTX
python ppt | Python Course In Ghaziabad | Scode Network Institute
Scode Network Institute
 
PPTX
Python basics
Manisha Gholve
 
PPT
python-ppt.ppt
MohammadSamiuddin10
 
PPT
python-ppt.ppt
MohammadSamiuddin10
 
PPTX
PYTHON PROGRAMMING.pptx
swarna627082
 
PDF
Introduction to python programming
Srinivas Narasegouda
 
PDF
Intro-to-Python-Part-1-first-part-edition.pdf
ssuser543728
 
PPTX
BASICS OF PYTHON usefull for the student who would like to learn on their own
Nandini485510
 
PPTX
Python programming language introduction unit
michaelaaron25322
 
PPTX
introduction to python programming concepts
GautamDharamrajChouh
 
Python Programming
Saravanan T.M
 
INTRODUCTION TO PYTHON.pptx
Nimrahafzal1
 
Python basics
ssuser4e32df
 
Chapter 1-Introduction and syntax of python programming.pptx
atharvdeshpande20
 
Python - Module 1.ppt
jaba kumar
 
Fundamentals of Python Programming
Kamal Acharya
 
UNIT 1 .pptx
Prachi Gawande
 
Python Programming 1.pptx
Francis Densil Raj
 
Chapter1 python introduction syntax general
ssuser77162c
 
Introduction to Python Programming .pptx
NaynaSagarDahatonde
 
python ppt | Python Course In Ghaziabad | Scode Network Institute
Scode Network Institute
 
Python basics
Manisha Gholve
 
python-ppt.ppt
MohammadSamiuddin10
 
python-ppt.ppt
MohammadSamiuddin10
 
PYTHON PROGRAMMING.pptx
swarna627082
 
Introduction to python programming
Srinivas Narasegouda
 
Intro-to-Python-Part-1-first-part-edition.pdf
ssuser543728
 
BASICS OF PYTHON usefull for the student who would like to learn on their own
Nandini485510
 
Python programming language introduction unit
michaelaaron25322
 
introduction to python programming concepts
GautamDharamrajChouh
 

Recently uploaded (20)

PDF
CT-2-Ancient ancient accept-Criticism.pdf
DepartmentofEnglishC1
 
DOCX
🧩 1. Solvent R-WPS Office work scientific
NohaSalah45
 
PDF
Business Automation Solution with Excel 1.1.pdf
Vivek Kedia
 
PDF
Kafka Use Cases Real-World Applications
Accentfuture
 
PDF
SQL for Accountants and Finance Managers
ysmaelreyes
 
PDF
IT GOVERNANCE 4-2 - Information System Security (1).pdf
mdirfanuddin1322
 
PPTX
covid 19 data analysis updates in our municipality
RhuAyungon1
 
PDF
Orchestrating Data Workloads With Airflow.pdf
ssuserae5511
 
PPTX
Cultural Diversity Presentation.pptx
Shwong11
 
PPTX
Krezentios memories in college data.pptx
notknown9
 
PPTX
Data anlytics Hospitals Research India.pptx
SayantanChakravorty2
 
PPTX
Generative AI Boost Data Governance and Quality- Tejasvi Addagada
Tejasvi Addagada
 
PPTX
Module-2_3-1eentzyssssssssssssssssssssss.pptx
ShahidHussain66691
 
PPTX
Presentation.pptx hhgihyugyygyijguuffddfffffff
abhiruppal2007
 
PPTX
Project_Update_Summary.for the use from PM
Odysseas Lekatsas
 
PDF
Exploiting the Low Volatility Anomaly: A Low Beta Model Portfolio for Risk-Ad...
Bradley Norbom, CFA
 
PDF
Unlocking Insights: Introducing i-Metrics Asia-Pacific Corporation and Strate...
Janette Toral
 
PDF
5- Global Demography Concepts _ Population Pyramids .pdf
pkhadka824
 
PPTX
Data Analytics using sparkabcdefghi.pptx
KarkuzhaliS3
 
PPTX
办理学历认证InformaticsLetter新加坡英华美学院毕业证书,Informatics成绩单
Taqyea
 
CT-2-Ancient ancient accept-Criticism.pdf
DepartmentofEnglishC1
 
🧩 1. Solvent R-WPS Office work scientific
NohaSalah45
 
Business Automation Solution with Excel 1.1.pdf
Vivek Kedia
 
Kafka Use Cases Real-World Applications
Accentfuture
 
SQL for Accountants and Finance Managers
ysmaelreyes
 
IT GOVERNANCE 4-2 - Information System Security (1).pdf
mdirfanuddin1322
 
covid 19 data analysis updates in our municipality
RhuAyungon1
 
Orchestrating Data Workloads With Airflow.pdf
ssuserae5511
 
Cultural Diversity Presentation.pptx
Shwong11
 
Krezentios memories in college data.pptx
notknown9
 
Data anlytics Hospitals Research India.pptx
SayantanChakravorty2
 
Generative AI Boost Data Governance and Quality- Tejasvi Addagada
Tejasvi Addagada
 
Module-2_3-1eentzyssssssssssssssssssssss.pptx
ShahidHussain66691
 
Presentation.pptx hhgihyugyygyijguuffddfffffff
abhiruppal2007
 
Project_Update_Summary.for the use from PM
Odysseas Lekatsas
 
Exploiting the Low Volatility Anomaly: A Low Beta Model Portfolio for Risk-Ad...
Bradley Norbom, CFA
 
Unlocking Insights: Introducing i-Metrics Asia-Pacific Corporation and Strate...
Janette Toral
 
5- Global Demography Concepts _ Population Pyramids .pdf
pkhadka824
 
Data Analytics using sparkabcdefghi.pptx
KarkuzhaliS3
 
办理学历认证InformaticsLetter新加坡英华美学院毕业证书,Informatics成绩单
Taqyea
 
Ad

PART - 1 Python Introduction- Variables- Data types - Numeric- String- Boolean.pptx.pdf

  • 3. PROGRAMMING LANGUAGE •A programming language is a type of written language that tells computers what to do. •A "program" in general, is a sequence of instructions written so that a computer can perform certain task.
  • 5. Types of programming languages The programming languages are broadly classified into three types, • Low-level language • High-level language • Middle-level language
  • 6. Low-level langu age It is machine-dependent. It works based on the binary number 0’s and 1’s. The processor runs low-level programs directly without the need of a compiler or interpreter so the program written in low-level language can be run very fast.
  • 7. High-level programming language High-level programming language (HLL) is designed for developing user-friendly software programs and websites. This programming language requires a compiler or interpreter to translate the program into machine language (execute the program). Example: Python, Java, JavaScript, PHP, C#, C++, etc.
  • 8. Middle-level programming language Middle-level programming language lies between the low-level programming language and the high-level programming language. It is also known as the intermediate programming language and pseudo-language. A middle-level programming language's advantages are that it supports the features of high-level programming, it is a user-friendly language, and is closely related to machine language and human language. Example: C, C++, language
  • 9. PYTHON Interpreted programming language Dynamic Object Oriented Versatile scripting language Multiple programming paradigms.
  • 10. PROGRAMMING VS SCRIPTING Scripts are few lines of code used within a program. These scripts are written to automate some particular tasks within the program. Programming languages are a set of code/instructions for the computer that are compiled at runtime. Thus an exe file is created
  • 12. HISTORY Python was created by Guido van Rossum, and first released on February 20, 1991. While you may know the python as a large snake, the name of the Python programming language comes from an old BBC television comedy sketch series called Monty Python's Flying Circus.
  • 15. FEATURES Easy to read and learn Free and Open source Cross platform Large standard library Extensible GUI Programming support
  • 16. APPLICATIONS Web applications GUI based desktop applications(Games, Scientific Applications) Operating Systems Enterprise and Business applications Audio or video based applications 3D CAD application
  • 18. DOWNLOADING AND INSTALLATION Visit the link https://www.python.org
  • 19. Ways to run Python Scripts 1. Command Line [python script.py] ✔ Open a terminal or command prompt. ✔ Navigate to the directory containing your Python script using the cd command. 2. IDLE (Python's Integrated Development and Learning Environment): ✔ Open IDLE and use the "File" menu to open your script, then run it. 3. Jupyter Notebooks [Using interpreter interactively] ✔ If you are using Jupyter Notebooks, you can run individual cells or the entire notebook. ✔ Use the "Run" button or press Shift + Enter to execute a cell.
  • 20. IDE An integrated development environment (IDE) is a software application that helps programmers develop software code efficiently. It increases developer productivity by combining capabilities such as software editing, building, testing, and packaging in an easy-to-use application.
  • 21. ANACONDA PYTHON Anaconda is a distribution of the Python and R programming languages for scientific computing (data science, machine learning applications, large-scale data processing, predictive analytics, etc.), that aims to simplify package management and deployment.
  • 24. VARIABLE • In Python, variables are a storage placeholder for texts and numbers. • It must have a name so that you are able to find it again • The variable is always assigned with the equal sign, followed by the value of the variable. • A variable is created the moment we first assign a value to it. Example: a=10 b=“IBM” print(a) Print(b)
  • 25. RULES FOR CREATING VARIABLES Must start with a letter or the underscore character Cannot start with a number Can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ ) Case-sensitive (name, Name and NAME are three different variables) The reserved words(keywords) cannot be used naming the variable
  • 26. Assigning a single value to multiple variables Example:: x=y=z= 100 print(x) print(y) print(z)
  • 27. Assigning different values to multiple variables Example: x, y, z =10, 20.20, “IBM CE” print(x) print(y) print(z)
  • 28. Can we use same name for different types? If we use same name, the variable starts referring to new value and type. Example: x=23 x=“salary” print(x)
  • 29. How does + operator work with variables Example: x = 100 y = 200 print(x + y) x = "IBM" y = "CE" print(x + y)
  • 30. Can we use + for different types also? ‘+’ used for adding different data types will produce an error. Example: age= 10 name = "David" print(age+name) OUTPUT: TypeError: unsupported operand type(s) for +: 'int' and 'str'
  • 31. Keywords •Keywords are special reserved words which convey a special meaning to the compiler/interpreter. •Each keyword have a special meaning and a specific operation. import keyword print(keyword.kwlist)
  • 33. IO OPERATIONS •print( ) - Used for output operation •input( ) - Used for input operations. name = input() number = int(input()) print ('my name is:’, name, 'and my age is:', number)
  • 35. DATA TYPES Immutable Data Types Numeric types(int, float, complex) Tuple String and Boolean Mutable Data Types List Dictionary Set
  • 36. Data Types:- Variables will hold values, and every value has its own data-type. Python is a dynamically typed language Hence we do not need to define the type of the variable while declaring it. The interpreter implicitly binds the value with its type.
  • 37. a = 5 The variable a holds integer value five and we did not define its type. Python interpreter will automatically interpret variables a as an integer type. Python enables us to check the type of the variable used in the program. Python provides us the type() function, which returns the type of the variable passed.
  • 38. Numeric Datatype :- Numeric values are known as numbers. There are three types. integer, float, and complex (They may be +ve /-ve) Python provides the type() function to know the data-type of the variable.
  • 39. Example: Output: x=1 #integer <Class ‘int’> y=13.6 #float <Class ‘float’> z=6+1j #complex <Class ‘complex’> print(type(x)) print(type(y)) print(type(z))
  • 40. Comments Helps explaining Python code. make the code more readable. prevent execution when testing code. Comments starts with a #, and Python will ignore them
  • 41. Constants A constant is a special type of variable whose value cannot be changed. import constant print(constant.PI) # prints 3.14 print(constant.GRAVITY) # prints 9.8
  • 42. Type Conversion:- #convert from int to float: x = 1 a = float(x) print(a) #convert from float to int: y = 2.8 b = int(y) print(b) #convert from int to complex: z = 1 c = complex(z) print(c)
  • 43. Points to Remember:- All the keywords must be used as they have defined. (Uppercase and Lower Case) Keywords should not be used as identifiers like variable names, functions name, class name, etc. The meaning of each keyword is fixed, we can not modify or remove it.
  • 44. Booleans Booleans represent one of two values: True or False. Input: Output: print(10 > 9) True print(10 == 9) False
  • 45. Strings String is a sequence of characters. String may contain alphabets, numbers and special characters. Usually strings are enclosed within a single quotes and double quotes. Example: a= “hello world‟ b= ‘Python’ We can display a string literal with the print() function.
  • 46. Example 1: String1 ="I'm a technical lead" print(String1) Example 2 : String2 ='I'm a technical lead’ print(String2) Example 3: String3 ='''I'm a technical lead and “tester”"' print(String3) Example 4: String4 =‘‘‘python for datascience ”’ print(String4)
  • 47. OUTPUT for Example 1: I'm a technical lead OUTPUT for Example 2: SyntaxError: invalid syntax OUTPUT for Example 3: I'm a technical lead and "tester" OUTPUT for Example 4: python for datascience
  • 48. Multiline Strings We can assign a multiline string to a variable by using three quotes. a = ""“You get What you work for Not what you wish for.""" print(a)
  • 49. Strings in Python are arrays of bytes representing unicode characters. Python does not have a character data type, a single character is simply a string with a length of 1. Square brackets can be used to access elements of the string. Indexing:- a = "Hello, World!" print(a[1])
  • 50. Accessing characters in Python Individual characters of a String can be accessed by using the method of Indexing. To access a range of characters in the String, method of slicing is used.( done by using a Slicing operator (colon)).
  • 51. Strings indexing and splitting The indexing of the python strings starts from 0.
  • 52. b = "Hello, World!" print(b[3:-5]) Slicing:- b = "Hello,World!" print(b[2:5]) b = "Hello,World!" print(b[:5]) b = "Hello,World!" print(b[2:])
  • 54. Deleting/Updating from a String Updation or deletion of characters from a String is not allowed. This will cause an error because item assignment or item deletion from a String is not supported. Although deletion of entire String is possible with the use of a built-in del keyword. This is because Strings are immutable, hence elements of a String cannot be changed once it has been assigned. Only new strings can be reassigned to the same name.
  • 55. Deleting Entire String:(using del keyword) Example: String1 = "Hello, I'm john" print(String1) # Deleting entire String del String1 print("nDeleting the entire string ") print(String1)
  • 56. OUTPUT: Hello, I'm john Deleting the entire string NameError: name 'String1' is not defined
  • 58. NOTE ✔ While accessing an index out of the range will cause an Index Error. ✔ Only Integers are allowed to be passed as an index, float or other types will cause a TypeError.
  • 59. String operations Concatenation of Two or More Strings Removes any whitespace from the beginning or the end The length of a string Strings in lower case Strings in upper case Replaces a string with another string Splits the string into substrings
  • 60. Concatenation of Two or More Strings Joining of two or more strings into a single one is called concatenation. Example: str1 = "python" str2 ="programming" # using + print("str1 + str2 = ", str1 + str2) OUTPUT: str1 + str2 = pythonprogramming
  • 61. Example: str1 = "python" # using * print('str1 * 3 =', str1 * 3) OUTPUT: str1 * 3 = pythonpythonpython
  • 62. Removes any whitespace from the beginning or the end Example: A = “ Hello, World! ” print(A) a = " Hello, World! “ print(a.strip()) OUTPUT: Hello, World! Hello, World!
  • 63. To find the the length of a string Example: a = "Hello, World!" print(len(a)) OUTPUT: 13
  • 64. Strings in lower case Example: a = "HELLO, World!" print(a.lower()) OUTPUT: hello, world!
  • 65. Strings in upper case Example: a = "Hello, World!" print(a.upper()) OUTPUT: HELLO, WORLD!
  • 66. Replaces a string with another string Example: a = "Hello, World!" print(a.replace("H", “F")) OUTPUT: Fello, World!
  • 67. Splits the string into substrings Example: a = "Hello, World!" print(a.split(",")) OUTPUT: ['Hello', ' World!']
  • 68. String Methods In Python:-
  • 69. String Methods In Python:-
  • 70. String Methods In Python:-
  • 71. String Methods In Python:-