SlideShare a Scribd company logo
Lecture 4 python string (ewurc)
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

ODP
Regex Presentation
PPTX
Regular Expression
PPTX
Regular expression examples
PDF
Python - Lecture 5
PDF
Week-2: Theory & Practice of Data Cleaning: Regular Expressions in Practice
PDF
Week-2: Theory & Practice of Data Cleaning: Regular Expressions in Theory
PPTX
Presentation more c_programmingcharacter_and_string_handling_
PPTX
Regular expressions
Regex Presentation
Regular Expression
Regular expression examples
Python - Lecture 5
Week-2: Theory & Practice of Data Cleaning: Regular Expressions in Practice
Week-2: Theory & Practice of Data Cleaning: Regular Expressions in Theory
Presentation more c_programmingcharacter_and_string_handling_
Regular expressions

What's hot (20)

PPT
Regular expressions
PPTX
Finaal application on regular expression
PDF
Left factor put
PPT
Regular Expressions grep and egrep
PPTX
Regular Expressions 101 Introduction to Regular Expressions
PPTX
Regular expressions
PPT
16 Java Regex
PPT
Introduction to regular expressions
PPTX
Introduction to Regular Expressions
PPT
Textpad and Regular Expressions
PPTX
Regex posix
PPTX
Java: Regular Expression
PPTX
Compiler design syntax analysis
PPTX
Bioinformatica p2-p3-introduction
PPTX
Regular expressions
PPT
Regex Intro
PPT
Regular Expressions
PPTX
Regular expressions
PDF
3 character strings and formatted input output
PDF
slide share test
Regular expressions
Finaal application on regular expression
Left factor put
Regular Expressions grep and egrep
Regular Expressions 101 Introduction to Regular Expressions
Regular expressions
16 Java Regex
Introduction to regular expressions
Introduction to Regular Expressions
Textpad and Regular Expressions
Regex posix
Java: Regular Expression
Compiler design syntax analysis
Bioinformatica p2-p3-introduction
Regular expressions
Regex Intro
Regular Expressions
Regular expressions
3 character strings and formatted input output
slide share test
Ad

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

PPT
String manipulation techniques like string compare copy
PDF
0-Slot21-22-Strings.pdf
PPTX
All_About_Strings_in_C_Programming.pptxn
PDF
Character Array and String
PDF
stringsinpython-181122100212.pdf
PPTX
Module-2_Strings concepts in c programming
PPT
CPSTRINGSARGAVISTRINGS.PPT
PPT
BHARGAVISTRINGS.PPT
PDF
Strings in python
PPT
Cfbcgdhfghdfhghggfhghghgfhgfhgfhhapter11.PPT
PPT
THE FORMAT AND USAGE OF STRINGS IN C.PPT
PPT
Chapterabcdefghijklmnopqrdstuvwxydanniipo
PDF
Cse115 lecture14strings part01
PPTX
Strings CPU GTU
PDF
python1uhaibueuhERADGAIUSAERUGHw9uSS.pdf
PPTX
Python Strings.pptx
PPTX
fundamentals of c programming_String.pptx
PPTX
Handling of character strings C programming
PPT
CP-STRING (1).ppt
PPT
CP-STRING.ppt
String manipulation techniques like string compare copy
0-Slot21-22-Strings.pdf
All_About_Strings_in_C_Programming.pptxn
Character Array and String
stringsinpython-181122100212.pdf
Module-2_Strings concepts in c programming
CPSTRINGSARGAVISTRINGS.PPT
BHARGAVISTRINGS.PPT
Strings in python
Cfbcgdhfghdfhghggfhghghgfhgfhgfhhapter11.PPT
THE FORMAT AND USAGE OF STRINGS IN C.PPT
Chapterabcdefghijklmnopqrdstuvwxydanniipo
Cse115 lecture14strings part01
Strings CPU GTU
python1uhaibueuhERADGAIUSAERUGHw9uSS.pdf
Python Strings.pptx
fundamentals of c programming_String.pptx
Handling of character strings C programming
CP-STRING (1).ppt
CP-STRING.ppt
Ad

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

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

Recently uploaded (20)

PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
Open folder Downloads.pdf yes yes ges yes
PPTX
Onica Farming 24rsclub profitable farm business
PPTX
Cardiovascular Pharmacology for pharmacy students.pptx
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PPTX
COMPUTERS AS DATA ANALYSIS IN PRECLINICAL DEVELOPMENT.pptx
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Pre independence Education in Inndia.pdf
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
DOCX
UPPER GASTRO INTESTINAL DISORDER.docx
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
Pharma ospi slides which help in ospi learning
PPTX
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
PDF
Business Ethics Teaching Materials for college
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
Piense y hagase Rico - Napoleon Hill Ccesa007.pdf
Pharmacology of Heart Failure /Pharmacotherapy of CHF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Open folder Downloads.pdf yes yes ges yes
Onica Farming 24rsclub profitable farm business
Cardiovascular Pharmacology for pharmacy students.pptx
Week 4 Term 3 Study Techniques revisited.pptx
COMPUTERS AS DATA ANALYSIS IN PRECLINICAL DEVELOPMENT.pptx
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
STATICS OF THE RIGID BODIES Hibbelers.pdf
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Pre independence Education in Inndia.pdf
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
UPPER GASTRO INTESTINAL DISORDER.docx
102 student loan defaulters named and shamed – Is someone you know on the list?
Pharma ospi slides which help in ospi learning
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
Business Ethics Teaching Materials for college
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Renaissance Architecture: A Journey from Faith to Humanism
Piense y hagase Rico - Napoleon Hill Ccesa007.pdf

Lecture 4 python string (ewurc)

  • 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 [email protected] 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