Course Content
Introduction to Python
Introduction to Python
3. Conditional Statements
Boolean Data TypeChallenge: Comparison OperatorsCombining ConditionsChallenge: Logical OperatorsMembership Operators and Types ComparisonSimple if/else ExpressionsChallenge: Grocery StoreChallenge: Odd and Evenif/elif/else ExpressionsChallenge: Grocery Store ExtendedChallenge: Positive, Negative or Zero
String Indexing
Suppose we have a string. Let's delve into how to work with it. First up, let's understand how to access specific characters within a string.
To access a specific character in a string, use square brackets with an index number inside. Remember, the index number is not the actual position of the character because indexing in Python starts at 0. Consider the example below for clarity.
In Python, the index is always one less than the actual position. For instance, we can retrieve several letters from the word in the example above.
# Initial string site = "codefinity" # Get the letters 'o' and 'y' print(site[1], site[9])
Everything was clear?
Thanks for your feedback!
Section 2. Chapter 8