I guess he’s just not your type.

--Originally published at Carolina's Blog Site

In Python, everything is a value==object. Values are classified into classes or types of data. There are 5 standard types of data:

  • Numbers
  • Strings
  • Lists
  • Tuples
  • Dictionaries

Numbers: The 2 most common types of number are the integer and the float (decimal points), but there’s also long (long integers) and complex (complex numbers)

Strings are a collection of characters stringed together that can be used to store like, anything. To enter a string, use “” or ”.  Btw, adding strings together is called concatenation. You can refer to a certain part of a string by using the index operator to get one character, e.g. [1], or by slicing it to get groups of characters, e.g. [1:3].

Lists are used to store an indexed list of items. They are created using [] and separating items with ,,,. They are mutable. The certain item in the list can be accessed by using its index in square brackets.

  • To check if an item is in a list, use the in operator, which returns True if the item is in the list, and False if it is not.
  • Append method adds an item to the end of an existing list, e.g. nums.append(4).
  • Len function to get the number of items in a list, e.g. print (len(nums)).
  • The insert method allows you to insert a new item at any position in the list.
  • The index method finds the first occurrence of a list item and returns its index.
  • max(list): Returns the list item with the maximum value.
  • min(list): Returns the list item with minimum value.
  • list.count(obj): Returns a count of how many times an item occurs in a list.
  • list.remove(obj): Removes an object from a list.
  • list.reverse(): Reverses objects in a list.

Tuples are lists,

they immutable, and they use ().

Dictionaries: are the relation between a key and a value given to that key, and the’re enclosed by {}. To retrieve the value of the key, use []. E.g.

>>>my_dct= {‘ramen’: 5, ‘pasta’: 3}

>>>my_dct [‘pasta’]

3