Previous Module
Next Module

COMPUTER SYSTEMS: Encoding and compression

COMPUTER SYSTEMS: Network topologies

COMPUTER SYSTEMS: Wired and wireless networks, protocols, and layers

COMPUTER SYSTEMS: Threats to computer systems and networks

COMPUTER SYSTEMS: Operating systems and utility software

ALGORITHMS AND PROGRAMMING: Types of data

ALGORITHMS AND PROGRAMMING: Producing robust programs

ALGORITHMS AND PROGRAMMING: Designing, creating, and refining algorithms

ALGORITHMS AND PROGRAMMING: Artificial Intelligence (AI)

  • String: a sequence of characters (letters, numbers, symbols). Strings are written inside quotation marks. In Python, strings are immutable (meaning they cannot be changed directly).

name = “Ada

message = “Hello

  • Concatenation: joining two or more strings together.

= “Ada

Lovelace

first_name + “ ” + last_name # “Ada Lovelace”

  • Indexing: each character has an index number, starting from 0.
  • Slicing: extracting parts of a string using indexes. This is used for extracting initials, substrings, etc.

word = “computer

 
 

print(word[0]) # C

print(word[3]) # p

print(word[–1]) # r

 
 

print(word[0:4]) # Comp

print(word[3:]) # puter

print(word[:8]) # Compute

 
 

print(len(text)) # 8

  • Other common methods of string manipulation are: 
    • upper() and lower() to change to uppercase/lowercase. 
    • strip() to remove spaces 
    • find() to locate a character or substring. This returns the index of the first match, or returns –1 if not found.

Unlock String manipulation

Subscribe to SnapRevise+ to get immediate access to the rest of this resource.

Premium accounts get immediate access to this resource.

Previous Module
Next Module