Blog Detail

September 1, 2023

Python Data Types Exercises

  • What is the output of this code?

                    hashtag = "#Python"
    hashtag_length = len(hashtag)
  • What is the output of this code?

                    phone_number = '555-1234'
    phone_number_length = len(phone_number)
  • When using the len() function in Python, does it count spaces as well?

  • What is the output of this program?

                    phone_number = '87654321'
    is_valid_number = phone_number.isdigit()
  • Does Python run this code?

                    is_valid_number = '87654321'.isdigit()
  • Is the following statement accurate?
    The len() function in Python is used to check if a string contains only digits. If the string consists solely of digits, the function returns True; otherwise, it returns False.

  • What does the index of a character in a string represent in Python?

  • What is the index of comma?

                    sentence = "Hello, world!"
    index = sentence.find(",")
  • Python Exercises for Data Types

    • If you’ve faced difficulties with these exercises, take a look at Data Types Module on my Python course.

    You can also share ‘Python Data Types’ Exercises on your:
    X (Twitter)TelegramLinkedinFacebook – or on your favorite platform…

    Happy Coding!
    Behnam Khani