Table of Contents

, , , , , , , , ,

About the Club

Python Club Topics - Data types

Questions

  1. What a data type?

Data Types

  1. string: Set of characters with letters, numbers, or symbols ( eg. numbers or numb3rs or numb3rs! )
  2. integer: Numbers without a decimal point ( eg. 39 )
  3. float: Numbers with a decimal ( eg. 3.9 )
  4. list: Set of multiple values in a single variable name ( eg. school_subjects = [ 0, “Math”, 1, “Science”, 2, “P.E.”, 3, “Social Studies” ] )
    1. Also known as an “array”
  5. tuple: Set of multiple values that cannot be changed ( eg. ( 0, “Math”, 1, “Science”, 2, “P.E” ) )
  6. sequence: An ordered collection of items, capable of being accessed by index. Common sequence types in Python include lists, tuples, and strings.
  7. set: An unordered collection of unique elements. It is similar to a list or tuple, but it does not allow duplicate values. Sets are useful for tasks such as removing duplicates from a sequence, testing for membership, and performing mathematical set operations like union, intersection, and difference.
  8. boolean: Can only have 1 value of True or False ( eg. favorite_color = True )

String

A string veriable is one that contains letters and numbers as characters, like words in a sentence.
  1. Use the type() function to find the current type of a variable
    x = "Hello world!"
    print(type(x))
  2. You can also get the *length* of the string by using the len() function
    x = "Hello world!"
    print(len(x))

Integer

  1. Use the type() function to find the current type of a variable
    x = 5
    print(type(x))

Float

  1. Use the type() function to find the current type of a variable
    x = 21.3
    print(x)
    print(int(x))

Boolean

  1. Booleans store the value of True or False
    1. Expressions are evaluated to one of these values
      print(10 > 9)
      print(10 == 9)
      print(10 < 9)
    2. All values are True except for the following conditions.
      1. Empty string
      2. Empty list ( We'll cover lists in the next section )
      3. Number 0
      4. Explicitly setting a value of False
      5. Expressions that evalute to False