SlideShare a Scribd company logo
Python
Lecture 4
Problem Set 4: String
Topic
• Membership Operator
• String Constants
• String Boolean Methods
• String Methods
• Problem Set 4: String (11)
Membership Operator
• in
• not in
Character input/ output and ASCII value
char = input()
print(char)
char = input()
print(char)
print(ord(char))
char = 'A'
print(ord(char))
char = input()
print(char, " = ", ord(char))
Character input/ output and ASCII value 2
for c in range(33,48):
print(chr(c), end = ' ')
print()
for c in range(48,58):
print(chr(c), end = ' ')
print()
for c in range(58,65):
print(chr(c), end = ' ')
print()
for c in range(65,91):
print(chr(c), end = ' ')
print()
for c in range(91,97):
print(chr(c), end = ' ')
print()
for c in range(97,123):
print(chr(c), end = ' ')
print()
ASCII
c = '0'
print("Char ASCII")
while c<='9':
print(f'{c:4} {ord(c):3}')
c = chr(ord(c) + 1)
ASCII
c = 'A'
print("Char ASCII")
while c<='Z':
print(f'{c:4} {ord(c):3}')
c = chr( ord(c) + 1)
c = 'a'
print("Char ASCII")
while c<='z':
print(f'{c:4} {ord(c):3}')
c = chr( ord(c) + 1)
String constants
• string.ascii_lowercase
• abcdefghijklmnopqrstuvwxyz
• string.ascii_uppercase
• ABCDEFGHIJKLMNOPQRSTUVWXYZ
• string.ascii_letters
• ascii_lowercase, ascii_uppercase
String constants
• string.digits
• 0123456789
• string.hexdigits
• 0123456789abcdefABCDEF
• string.octdigits
• 01234567
String constants
• string.punctuation
• ! " # $ % & ' ( ) * + , - . / : ; < = > ? @ [  ] ^ _ ` { | } ~
• string.whitespace
• space, tab, linefeed, return, formfeed, vertical tab
• string.printable
• String of ASCII characters which are considered printable. This is a
combination of digits, ascii_letters, punctuation, and whitespace.
String constants
import string
for c in string.ascii_lowercase:
print(c,end=' ')
String constants 1
import string
char = 'A'
if char in string.ascii_letters:
print("Alphabet")
else:
print("Not")
char = '5'
if char in string.digits:
print("Digit")
else:
print("Not")
char = '?'
if char not in string.ascii_letters and char
not in string.digits :
print("Special")
else:
print("Not")
String constants 2
char = 'A'
if char in string.ascii_uppercase:
print("Upper Case")
else:
print("Not")
char = 'a'
if char in string.ascii_lowercase:
print("Lower Case")
else:
print("Not")
vowel = 'aeiouAEIOU'
char = 'A'
if char in vowel:
print("Vowel")
else:
print("Not")
char = 'R'
if char not in vowel:
print("Consonant")
else:
print("Not")
String Matching
str1 = "EWU"
str2 = "EWU"
if str1 == str2:
print("Matched")
else:
print("Not Matched")
str1 = "EWU"
str2 = "ewu"
if str1 == str2:
print("Matched")
else:
print("Not Matched")
String Reverse
str = "EWU"
print(str[::-1])
str1 = "EWU"
str2 = str1[::-1]
print(str2)
String Methods
• https://docs.python.org/3.6/library/stdtypes.html#string-methods
• str.capitalize()
• Return a copy of the string with its first character capitalized and the rest lowercased.
• str.count(sub[, start[, end]])
• Return the number of non-overlapping occurrences of substring sub in the range
[start, end]. Optional arguments start and end are interpreted as in slice notation.
• str.find(sub[, start[, end]])
• Return the lowest index in the string where substring sub is found within the slice
s[start:end]. Optional arguments start and end are interpreted as in slice notation.
Return -1 if sub is not found.
• str.replace(old, new[, count])
String Methods
• string.upper()
• string.lower()
String Boolean Methods
• str.isalnum()
• String consists of only alphanumeric characters (no symbols)
• str.isalpha()
• String consists of only alphabetic characters (no symbols)
• str.isdecimal()
• String consists of only decimal characters
• str.isspace()
• String consists of only whitespace characters
String Boolean Methods
• str.islower()
• String’s alphabetic characters are all lower case
• str.isupper()
• String’s alphabetic characters are all upper case
• string.istitle()
• String is in title case
String Function
• ord(char)
• chr(num)
Problem Set 4: String (11)
• Character input/ output and ASCII value.
• Check is a Character Alphabet/ Digit/ Special Character.
• Check is an Alphabet Vowel or Consonant.
• Check is an Alphabet Upper or Lower Case.
• Input/ Output String and count number of character (String Length count).
• Count Upper and Lower Case in a sentence.
• Change Case (Upper Case to Lower Case).
• String Matching
• String Reverse
• Palindrome
• Word Sorting (Dictionary)
Any Question?
Prepared by
Mun Al Mamun
President
East West University Robotics Club
munewu@gmail.com
T h i s s l i d e i s p r o v i d e a s a c o u r s e
m a t e r i a l i n t h e w o r k s h o p
“ W o r k s h o p O n P y t h o n P r o g r a m m i n g ”
O r g a n i z e d b y
E a s t W e s t U n i v e r s i t y R o b o t i c s C l u b

More Related Content

What's hot

Regular expressions
Regular expressionsRegular expressions
Regular expressionsRaj Gupta
 
Finaal application on regular expression
Finaal application on regular expressionFinaal application on regular expression
Finaal application on regular expression
Gagan019
 
Regular Expressions grep and egrep
Regular Expressions grep and egrepRegular Expressions grep and egrep
Regular Expressions grep and egrepTri Truong
 
Regular Expressions 101 Introduction to Regular Expressions
Regular Expressions 101 Introduction to Regular ExpressionsRegular Expressions 101 Introduction to Regular Expressions
Regular Expressions 101 Introduction to Regular Expressions
Danny Bryant
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
Brij Kishore
 
16 Java Regex
16 Java Regex16 Java Regex
16 Java Regexwayn
 
Introduction to regular expressions
Introduction to regular expressionsIntroduction to regular expressions
Introduction to regular expressions
Ben Brumfield
 
Introduction to Regular Expressions
Introduction to Regular ExpressionsIntroduction to Regular Expressions
Introduction to Regular Expressions
Matt Casto
 
Textpad and Regular Expressions
Textpad and Regular ExpressionsTextpad and Regular Expressions
Textpad and Regular Expressions
OCSI
 
Regex posix
Regex posixRegex posix
Regex posix
sana mateen
 
Java: Regular Expression
Java: Regular ExpressionJava: Regular Expression
Java: Regular ExpressionMasudul Haque
 
Compiler design syntax analysis
Compiler design syntax analysisCompiler design syntax analysis
Compiler design syntax analysis
Richa Sharma
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
Eran Zimbler
 
3 character strings and formatted input output
3  character strings and formatted input output3  character strings and formatted input output
3 character strings and formatted input output
MomenMostafa
 
slide share test
slide share testslide share test
slide share test
DreamMalar
 

What's hot (20)

Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
Finaal application on regular expression
Finaal application on regular expressionFinaal application on regular expression
Finaal application on regular expression
 
Left factor put
Left factor putLeft factor put
Left factor put
 
Regular Expressions grep and egrep
Regular Expressions grep and egrepRegular Expressions grep and egrep
Regular Expressions grep and egrep
 
Regular Expressions 101 Introduction to Regular Expressions
Regular Expressions 101 Introduction to Regular ExpressionsRegular Expressions 101 Introduction to Regular Expressions
Regular Expressions 101 Introduction to Regular Expressions
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
16 Java Regex
16 Java Regex16 Java Regex
16 Java Regex
 
Introduction to regular expressions
Introduction to regular expressionsIntroduction to regular expressions
Introduction to regular expressions
 
Introduction to Regular Expressions
Introduction to Regular ExpressionsIntroduction to Regular Expressions
Introduction to Regular Expressions
 
Textpad and Regular Expressions
Textpad and Regular ExpressionsTextpad and Regular Expressions
Textpad and Regular Expressions
 
Regex posix
Regex posixRegex posix
Regex posix
 
Java: Regular Expression
Java: Regular ExpressionJava: Regular Expression
Java: Regular Expression
 
Compiler design syntax analysis
Compiler design syntax analysisCompiler design syntax analysis
Compiler design syntax analysis
 
Bioinformatica p2-p3-introduction
Bioinformatica p2-p3-introductionBioinformatica p2-p3-introduction
Bioinformatica p2-p3-introduction
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
Regex Intro
Regex IntroRegex Intro
Regex Intro
 
Regular Expressions
Regular ExpressionsRegular Expressions
Regular Expressions
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
3 character strings and formatted input output
3  character strings and formatted input output3  character strings and formatted input output
3 character strings and formatted input output
 
slide share test
slide share testslide share test
slide share test
 

Similar to Lecture 4 python string (ewurc)

0-Slot21-22-Strings.pdf
0-Slot21-22-Strings.pdf0-Slot21-22-Strings.pdf
0-Slot21-22-Strings.pdf
ssusere19c741
 
Character Array and String
Character Array and StringCharacter Array and String
Character Array and String
Tasnima Hamid
 
stringsinpython-181122100212.pdf
stringsinpython-181122100212.pdfstringsinpython-181122100212.pdf
stringsinpython-181122100212.pdf
paijitk
 
Module-2_Strings concepts in c programming
Module-2_Strings concepts in c programmingModule-2_Strings concepts in c programming
Module-2_Strings concepts in c programming
CHAITRAB29
 
CPSTRINGSARGAVISTRINGS.PPT
CPSTRINGSARGAVISTRINGS.PPTCPSTRINGSARGAVISTRINGS.PPT
CPSTRINGSARGAVISTRINGS.PPT
Sasideepa
 
BHARGAVISTRINGS.PPT
BHARGAVISTRINGS.PPTBHARGAVISTRINGS.PPT
BHARGAVISTRINGS.PPT
Sasideepa
 
Strings in python
Strings in pythonStrings in python
Strings in python
Prabhakaran V M
 
Cse115 lecture14strings part01
Cse115 lecture14strings part01Cse115 lecture14strings part01
Cse115 lecture14strings part01
Md. Ashikur Rahman
 
Strings CPU GTU
Strings CPU GTUStrings CPU GTU
Strings CPU GTU
Maharshi Dave
 
Python Strings.pptx
Python Strings.pptxPython Strings.pptx
Python Strings.pptx
adityakumawat625
 
fundamentals of c programming_String.pptx
fundamentals of c programming_String.pptxfundamentals of c programming_String.pptx
fundamentals of c programming_String.pptx
JStalinAsstProfessor
 
Handling of character strings C programming
Handling of character strings C programmingHandling of character strings C programming
Handling of character strings C programming
Appili Vamsi Krishna
 
CP-STRING (1).ppt
CP-STRING (1).pptCP-STRING (1).ppt
CP-STRING (1).ppt
mounikanarra3
 
CP-STRING.ppt
CP-STRING.pptCP-STRING.ppt
CP-STRING.ppt
TAPANDDRAW
 
CP-STRING.ppt
CP-STRING.pptCP-STRING.ppt
CP-STRING.ppt
arunatluri
 
Python data handling
Python data handlingPython data handling
Python data handling
Prof. Dr. K. Adisesha
 
COm1407: Character & Strings
COm1407: Character & StringsCOm1407: Character & Strings
COm1407: Character & Strings
Hemantha Kulathilake
 
Strings in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothiStrings in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothi
Sowmya Jyothi
 

Similar to Lecture 4 python string (ewurc) (20)

0-Slot21-22-Strings.pdf
0-Slot21-22-Strings.pdf0-Slot21-22-Strings.pdf
0-Slot21-22-Strings.pdf
 
Character Array and String
Character Array and StringCharacter Array and String
Character Array and String
 
stringsinpython-181122100212.pdf
stringsinpython-181122100212.pdfstringsinpython-181122100212.pdf
stringsinpython-181122100212.pdf
 
Module-2_Strings concepts in c programming
Module-2_Strings concepts in c programmingModule-2_Strings concepts in c programming
Module-2_Strings concepts in c programming
 
CPSTRINGSARGAVISTRINGS.PPT
CPSTRINGSARGAVISTRINGS.PPTCPSTRINGSARGAVISTRINGS.PPT
CPSTRINGSARGAVISTRINGS.PPT
 
BHARGAVISTRINGS.PPT
BHARGAVISTRINGS.PPTBHARGAVISTRINGS.PPT
BHARGAVISTRINGS.PPT
 
Strings in python
Strings in pythonStrings in python
Strings in python
 
Cse115 lecture14strings part01
Cse115 lecture14strings part01Cse115 lecture14strings part01
Cse115 lecture14strings part01
 
Strings CPU GTU
Strings CPU GTUStrings CPU GTU
Strings CPU GTU
 
Python Strings.pptx
Python Strings.pptxPython Strings.pptx
Python Strings.pptx
 
fundamentals of c programming_String.pptx
fundamentals of c programming_String.pptxfundamentals of c programming_String.pptx
fundamentals of c programming_String.pptx
 
Handling of character strings C programming
Handling of character strings C programmingHandling of character strings C programming
Handling of character strings C programming
 
CP-STRING (1).ppt
CP-STRING (1).pptCP-STRING (1).ppt
CP-STRING (1).ppt
 
CP-STRING.ppt
CP-STRING.pptCP-STRING.ppt
CP-STRING.ppt
 
CP-STRING.ppt
CP-STRING.pptCP-STRING.ppt
CP-STRING.ppt
 
Ch09
Ch09Ch09
Ch09
 
Python data handling
Python data handlingPython data handling
Python data handling
 
COm1407: Character & Strings
COm1407: Character & StringsCOm1407: Character & Strings
COm1407: Character & Strings
 
14 strings
14 strings14 strings
14 strings
 
Strings in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothiStrings in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothi
 

More from Al-Mamun Riyadh (Mun)

Lecture 1 python arithmetic (ewurc)
Lecture 1 python arithmetic (ewurc)Lecture 1 python arithmetic (ewurc)
Lecture 1 python arithmetic (ewurc)
Al-Mamun Riyadh (Mun)
 
Prime Number (Sieve)
Prime Number (Sieve)Prime Number (Sieve)
Prime Number (Sieve)
Al-Mamun Riyadh (Mun)
 
Workshop on arduino (ewurc)
Workshop on arduino (ewurc)Workshop on arduino (ewurc)
Workshop on arduino (ewurc)
Al-Mamun Riyadh (Mun)
 
Lecture 6 python oop (ewurc)
Lecture 6 python oop (ewurc)Lecture 6 python oop (ewurc)
Lecture 6 python oop (ewurc)
Al-Mamun Riyadh (Mun)
 
Lecture 5 python function (ewurc)
Lecture 5 python function (ewurc)Lecture 5 python function (ewurc)
Lecture 5 python function (ewurc)
Al-Mamun Riyadh (Mun)
 
Lecture 3.1 python loop 1 (ewurc)
Lecture 3.1 python loop 1 (ewurc)Lecture 3.1 python loop 1 (ewurc)
Lecture 3.1 python loop 1 (ewurc)
Al-Mamun Riyadh (Mun)
 
Lecture 2 python conditional (ewurc)
Lecture 2 python conditional (ewurc)Lecture 2 python conditional (ewurc)
Lecture 2 python conditional (ewurc)
Al-Mamun Riyadh (Mun)
 
Lecture 0 python basic (ewurc)
Lecture 0 python basic (ewurc)Lecture 0 python basic (ewurc)
Lecture 0 python basic (ewurc)
Al-Mamun Riyadh (Mun)
 

More from Al-Mamun Riyadh (Mun) (8)

Lecture 1 python arithmetic (ewurc)
Lecture 1 python arithmetic (ewurc)Lecture 1 python arithmetic (ewurc)
Lecture 1 python arithmetic (ewurc)
 
Prime Number (Sieve)
Prime Number (Sieve)Prime Number (Sieve)
Prime Number (Sieve)
 
Workshop on arduino (ewurc)
Workshop on arduino (ewurc)Workshop on arduino (ewurc)
Workshop on arduino (ewurc)
 
Lecture 6 python oop (ewurc)
Lecture 6 python oop (ewurc)Lecture 6 python oop (ewurc)
Lecture 6 python oop (ewurc)
 
Lecture 5 python function (ewurc)
Lecture 5 python function (ewurc)Lecture 5 python function (ewurc)
Lecture 5 python function (ewurc)
 
Lecture 3.1 python loop 1 (ewurc)
Lecture 3.1 python loop 1 (ewurc)Lecture 3.1 python loop 1 (ewurc)
Lecture 3.1 python loop 1 (ewurc)
 
Lecture 2 python conditional (ewurc)
Lecture 2 python conditional (ewurc)Lecture 2 python conditional (ewurc)
Lecture 2 python conditional (ewurc)
 
Lecture 0 python basic (ewurc)
Lecture 0 python basic (ewurc)Lecture 0 python basic (ewurc)
Lecture 0 python basic (ewurc)
 

Recently uploaded

How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
kimdan468
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
chanes7
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
deeptiverma2406
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Marketing internship report file for MBA
Marketing internship report file for MBAMarketing internship report file for MBA
Marketing internship report file for MBA
gb193092
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 

Recently uploaded (20)

How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Marketing internship report file for MBA
Marketing internship report file for MBAMarketing internship report file for MBA
Marketing internship report file for MBA
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 

Lecture 4 python string (ewurc)

  • 1.
  • 3. Topic • Membership Operator • String Constants • String Boolean Methods • String Methods • Problem Set 4: String (11)
  • 5. Character input/ output and ASCII value char = input() print(char) char = input() print(char) print(ord(char)) char = 'A' print(ord(char)) char = input() print(char, " = ", ord(char))
  • 6. Character input/ output and ASCII value 2 for c in range(33,48): print(chr(c), end = ' ') print() for c in range(48,58): print(chr(c), end = ' ') print() for c in range(58,65): print(chr(c), end = ' ') print() for c in range(65,91): print(chr(c), end = ' ') print() for c in range(91,97): print(chr(c), end = ' ') print() for c in range(97,123): print(chr(c), end = ' ') print()
  • 7. ASCII c = '0' print("Char ASCII") while c<='9': print(f'{c:4} {ord(c):3}') c = chr(ord(c) + 1)
  • 8. ASCII c = 'A' print("Char ASCII") while c<='Z': print(f'{c:4} {ord(c):3}') c = chr( ord(c) + 1) c = 'a' print("Char ASCII") while c<='z': print(f'{c:4} {ord(c):3}') c = chr( ord(c) + 1)
  • 9. String constants • string.ascii_lowercase • abcdefghijklmnopqrstuvwxyz • string.ascii_uppercase • ABCDEFGHIJKLMNOPQRSTUVWXYZ • string.ascii_letters • ascii_lowercase, ascii_uppercase
  • 10. String constants • string.digits • 0123456789 • string.hexdigits • 0123456789abcdefABCDEF • string.octdigits • 01234567
  • 11. String constants • string.punctuation • ! " # $ % & ' ( ) * + , - . / : ; < = > ? @ [ ] ^ _ ` { | } ~ • string.whitespace • space, tab, linefeed, return, formfeed, vertical tab • string.printable • String of ASCII characters which are considered printable. This is a combination of digits, ascii_letters, punctuation, and whitespace.
  • 12. String constants import string for c in string.ascii_lowercase: print(c,end=' ')
  • 13. String constants 1 import string char = 'A' if char in string.ascii_letters: print("Alphabet") else: print("Not") char = '5' if char in string.digits: print("Digit") else: print("Not") char = '?' if char not in string.ascii_letters and char not in string.digits : print("Special") else: print("Not")
  • 14. String constants 2 char = 'A' if char in string.ascii_uppercase: print("Upper Case") else: print("Not") char = 'a' if char in string.ascii_lowercase: print("Lower Case") else: print("Not") vowel = 'aeiouAEIOU' char = 'A' if char in vowel: print("Vowel") else: print("Not") char = 'R' if char not in vowel: print("Consonant") else: print("Not")
  • 15. String Matching str1 = "EWU" str2 = "EWU" if str1 == str2: print("Matched") else: print("Not Matched") str1 = "EWU" str2 = "ewu" if str1 == str2: print("Matched") else: print("Not Matched")
  • 16. String Reverse str = "EWU" print(str[::-1]) str1 = "EWU" str2 = str1[::-1] print(str2)
  • 17. String Methods • https://docs.python.org/3.6/library/stdtypes.html#string-methods • str.capitalize() • Return a copy of the string with its first character capitalized and the rest lowercased. • str.count(sub[, start[, end]]) • Return the number of non-overlapping occurrences of substring sub in the range [start, end]. Optional arguments start and end are interpreted as in slice notation. • str.find(sub[, start[, end]]) • Return the lowest index in the string where substring sub is found within the slice s[start:end]. Optional arguments start and end are interpreted as in slice notation. Return -1 if sub is not found. • str.replace(old, new[, count])
  • 19. String Boolean Methods • str.isalnum() • String consists of only alphanumeric characters (no symbols) • str.isalpha() • String consists of only alphabetic characters (no symbols) • str.isdecimal() • String consists of only decimal characters • str.isspace() • String consists of only whitespace characters
  • 20. String Boolean Methods • str.islower() • String’s alphabetic characters are all lower case • str.isupper() • String’s alphabetic characters are all upper case • string.istitle() • String is in title case
  • 22. Problem Set 4: String (11) • Character input/ output and ASCII value. • Check is a Character Alphabet/ Digit/ Special Character. • Check is an Alphabet Vowel or Consonant. • Check is an Alphabet Upper or Lower Case. • Input/ Output String and count number of character (String Length count). • Count Upper and Lower Case in a sentence. • Change Case (Upper Case to Lower Case). • String Matching • String Reverse • Palindrome • Word Sorting (Dictionary)
  • 24. Prepared by Mun Al Mamun President East West University Robotics Club munewu@gmail.com T h i s s l i d e i s p r o v i d e a s a c o u r s e m a t e r i a l i n t h e w o r k s h o p “ W o r k s h o p O n P y t h o n P r o g r a m m i n g ” O r g a n i z e d b y E a s t W e s t U n i v e r s i t y R o b o t i c s C l u b