comp

    Cards (28)

    • What are the four common data types in Python?
      Integer, float, boolean, string
    • What is the difference between an integer and a float in Python?
      Integers are whole numbers; floats are decimals
    • What does the boolean data type store?
      True or false values only
    • What is a string in Python?
      A combination of letters, digits, symbols, and spaces
    • What happens if you store a digit as a string in Python?
      You cannot perform mathematical operations on it
    • What is the purpose of the Len function in Python?
      • To find the length of a string
      • Counts characters, including spaces and punctuation
    • How do you count the number of characters in a string variable named phrase?
      Use the Len function on phrase
    • How many characters are in the string "hi there"?
      Nine characters
    • Why does Python count nine characters in "hi there"?
      Seven letters, one space, one exclamation mark
    • What does the index position of a string start from in Python?
      Index position starts from zero
    • What character is at index position 0 in the string "learning Python"?
      Uppercase L
    • How do you access the character at index position 2 in a string?
      Use square brackets with the index number
    • What will happen if you access an index position that doesn't exist in a string?
      The program will crash with an error
    • What does the find method do in Python?
      Finds the index position of a character
    • What will the find method return if the character is not found in a string?
      Minus one
    • What is a substring?
      A section of a string
    • What does concatenation mean in Python?
      Linking strings together
    • How do you extract a substring from a string in Python?
      Use square brackets with two integers
    • How do you concatenate two strings in Python?
      Use the plus sign
    • What happens if you concatenate two strings without spaces?
      No spaces will appear in the new string
    • What is the ASCII character set?
      A character set with unique character codes
    • How do you find the character code of a character in Python?
      Use the ord function
    • What does the chr function do in Python?
      Returns the character for a given code
    • Why is it important to change data types in Python?
      To perform mathematical operations correctly
    • What does the input function do in Python?
      Stores user input as a string
    • What happens when you try to use the Len function on an integer?
      The program will crash with an error
    • How can you prevent a program from crashing when using Len on an integer?
      Convert the integer to a string first
    • What are the steps to change a string to an integer or float in Python?
      • Use the int function for integers
      • Use the float function for floats
      • Ensure the string represents a valid number
    See similar decks