KnowledgeCity

More Data Types

These lessons begin by explaining how to use the two most common sequence types in Python: the string and the list.

These lessons begin by explaining how to use the two most common sequence types in Python: the string and the list.  Strings, which are sequences of characters, employ the Unicode standard (which expands the much simpler ASCII standard) to represent nearly every alphabet in the world.  A discussion of mapping characters to numbers is followed by example code.  String formatting is covered using the format method of the string class and then the module concludes with a demonstration of the Python dictionary.

LEARNING OBJECTIVES:

  • Learn the purpose of the two most common sequence types in Python: the string and the list
  • Learn how to use the string and the list in Python
  • Understand the purpose of the Unicode standard and the ASCII standard
  • Understand how to map characters to numbers
  • Learn the format method of string class and what the dictionary is

Author: John Crabtree

Duration: 19m · 5 lessons
Level: Beginner
Language: English

Skills you’ll gain

Data Definition LanguageData EncodingData Format Description LanguageData Manipulation LanguageEncodingsPython (Programming Language)

What You'll Learn

  • Use the two most common sequence types in Python: the string and the list
  • Understand the purpose of the Unicode standard and how it expands the ASCII standard
  • Map characters to numbers when representing text
  • Apply the format method of the string class for string formatting
  • Work with Python dictionaries through dictionary basics

Key Takeaways

  • Strings and lists are the two most common sequence types in Python.
  • Strings are sequences of characters that use the Unicode standard, which expands the simpler ASCII standard, to represent nearly every alphabet in the world.
  • String formatting is performed using the format method of the string class.
  • The module concludes with a demonstration of the Python dictionary.

Frequently Asked Questions

What does this course cover?

It covers how to use Python's two most common sequence types, the string and the list, along with representing text using the Unicode and ASCII standards, mapping characters to numbers, string formatting with the format method of the string class, and Python dictionary basics.

What lessons are included?

The course includes String Basics, List Basics, Representing Text, String Formatting, and Dictionary Basics.

What skills will I gain from this course?

The course addresses skills including Python (Programming Language), Data Encoding, Encodings, Data Definition Language, Data Manipulation Language, and Data Format Description Language.

How is text represented in Python according to this course?

Strings are sequences of characters that employ the Unicode standard, which expands the simpler ASCII standard, to represent nearly every alphabet in the world, and the course discusses mapping characters to numbers followed by example code.

Transcript

Show transcript (free preview lesson)

Transcript of the free preview lesson. Remaining lessons unlock with the full course.

In Python, a string is a text sequence type, and you can use single quotes or you can use double quotes. But if you want to save your string, you need to associate that object with a variable. And it doesn't matter whether you use single or double quotes. You will notice here that when you display the contents of that variable, that it displays the string in the same way. So it doesn't really matter if you use single quotes or double quotes. In fact, you can use triple quotes. However, triple quotes are commonly used for block style comments because they allow you to comment your code with multiple lines. And that entire section in this case, in orange, in my editor will be ignored by the Python interpreter. So it is kind of like a multi-line version of the hashtag. With the hashtag you can tell the compiler to ignore the rest of the current line. Now there is a built-in function that is very handy. Called len, short for length. And you can use that to return the number of items in the sequence. In this case, the number of characters in my string. And so if I want to print the length of my pangram, by the way, that's commonly used to test out fonts because it has all the letters of the English language. Then you can just write a simple program like this and display the length of that string. Likewise, I can create a string of any length, even zero length. This is commonly known as the empty string, and you can use two single quotes or two double quotes right together. And you will see here that the length of the string, once I save my file, is zero. A zero length string. Now, one other cool thing that you can do with strings in Python, is you can print any single letter. You can access any of the items in the sequence. And so if I take my pangram, and if I want to look at the very first letter of that, it should be a capital T. I can use the square brackets. It's called the index operator, and just put a index value zero in there and that will access the first letter of that string. Now, it's really important to realize that programmers always begin counting with zero. So one, index one, is the second letter of that string. And of course, if you did something silly, like tried to access the second letter of the empty string, then you can imagine there are gonna be problems. You are going to generate an index error because that index, that letter, is out of range. Also, you can, with a string data type, you can use the plus sign. This is what's known as an overloaded operator because in the context of numbers, that means addition. But in the context of strings, that means concatenation. It's going to glue the string on the left to the string on the right. And on the left, I've got a string variable. On the right, I have a string literal.

Learn on the Go

Take your learning anywhere — the KnowledgeCity mobile app lets you watch lessons on the go.