[go: up one dir, main page]

0% found this document useful (0 votes)
39 views21 pages

Section 1 Part 2 Strings

The document provides an overview of string manipulation in Python, covering topics such as string characteristics, subscript operator, indexing, and slicing. It emphasizes that strings are immutable sequences of characters and includes examples to demonstrate various string operations. The learning outcome is to enable students to effectively use mathematical and string manipulation functions in Python.
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)
39 views21 pages

Section 1 Part 2 Strings

The document provides an overview of string manipulation in Python, covering topics such as string characteristics, subscript operator, indexing, and slicing. It emphasizes that strings are immutable sequences of characters and includes examples to demonstrate various string operations. The learning outcome is to enable students to effectively use mathematical and string manipulation functions in Python.
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/ 21

Strings

Python Programming

Prof. Supriya S. Telsang


supriya.telsang@vit.edu
Department of Computer Engineering

BRACT’S, Vishwakarma Institute of Technology, Pune

(An Autonomous Institute affiliated to Savitribai Phule Pune University)


(NBA and NAAC accredited, ISO 9001:2015 certified)

Department of Engineering Sciences and Humanities, VIT, Pune


Operators: (2Hrs)
Arithmetic Operators, relational Operators, Logical Operators, bitwise operators,
other stray operators, Operator Precedence, Mathematical Functions, Trigonometric
Functions, Random Number Functions, Strings in python : subscript operator,
indexing, slicing a string, string methods

Learning Outcome:
Demonstrate mathematical and string manipulation functions in Python.

Department of Engineering Sciences and Humanities, VIT, Pune


Strings

• String is a sequence of characters. It may contain


alphabets, numbers and special characters.
• Strings are enclosed in single and double quotes.
• Strings are immutable in nature.

Examples:

‘hello’
“college”

Department of Engineering Sciences and Humanities, VIT, Pune


Subscript operator

Subscript operator [ ] is used to access elements of


sequence like strings, list and tuples.

char my_string[10];
my_string=“Hello:;
print(my_string[1])

Output: e

Department of Engineering Sciences and Humanities, VIT, Pune


Indexing

Individual characters of the string can be accessed using indexing.

Example:

char name[10];
name=“vit college”
print(name[0]) output: v
print(name[4]) output: c
print(name[8]) output: e

Department of Engineering Sciences and Humanities, VIT, Pune


Slicing
A segment of s string is called slice.

Slicing is used to return/select/slice the particular substring based on user


requirements.

Syntax: string_variablename [start : end]

Example:

Name=“vit college”

print(“first 5 characters are”,name[:5]) output:vit c


nd th
print(“2 to 5 character”, name[2:5]) output: it c
Print(“excluding first 5 characters”,name[5:]) output:ollege

Department of Engineering Sciences and Humanities, VIT, Pune


Example

Department of Engineering Sciences and Humanities, VIT, Pune


String methods

Department of Engineering Sciences and Humanities, VIT, Pune


Department of Engineering Sciences and Humanities, VIT, Pune
String Functions and Methods

Department of Engineering Sciences and Humanities, VIT, Pune


Department of Engineering Sciences and Humanities, VIT, Pune
Department of Engineering Sciences and Humanities, VIT, Pune
Department of Engineering Sciences and Humanities, VIT, Pune
Department of Engineering Sciences and Humanities, VIT, Pune
Department of Engineering Sciences and Humanities, VIT, Pune
Department of Engineering Sciences and Humanities, VIT, Pune
Department of Engineering Sciences and Humanities, VIT, Pune
Department of Engineering Sciences and Humanities, VIT, Pune
Department of Engineering Sciences and Humanities, VIT, Pune
Department of Engineering Sciences and Humanities, VIT, Pune
THANK YOU !!!

Department of Engineering Sciences and Humanities, VIT, Pune

You might also like