Python Strings

Full Cup of Coding
3 min readJan 31, 2021

--

Today I started the taking the Angela Yu course 100 Days of Code — The Complete Python Pro Bootcamp for 2021.

Day 1 — Working With Variables to Manage Data

In the first day Angela reviews the following:

  1. Printing to the Console
  2. String Manipulation
  3. Python Input Function

At the end of the day you will build a Band Name Generator.

Printing To The Console

To print to the console just type the following command:

Running this code will print the string Hello World out to the console.

String Manipulation

To manipulate strings Python has some built-in methods:

Access

To access a character in a string provide the index.

For example if I were to print the character at the 0th index for the word “apple” then the console will return “a”.

Length

To get the length of the string use the len method.

For example if we get the length of apple the console will return 5.

Count

To count how many times a certain character is in a string use the count method.

For example if we count how many times p is in the word apple the console will return 2.

Replace

To replace a string we use the replace method.

For example if we want to change apple to ape we can replace ple with e to get the word ape.

Changing Uppercase and Lowercase Strings

To convert the entire string to uppercase we use the uppercase method and to convert to lowercase we use the lowercase method.

Input

To get an input from the user type the following command:

Band Name Generator

The project for today was to create a band name generator.

The Band Name generator asks for the city the user grew up in and the name of their pet. The console will then return the generated name.

You can click here to get all of the solutions on Github.

Have a great day and see you tomorrow!!

Photo by Florian Olivo on Unsplash

--

--

No responses yet