Python Data Types Cheat Sheet



Built-in Data Types. In programming, data type is an important concept. Variables can store data of different types, and different types can do different things. Python has the following data types built-in by default, in these categories. Python For Data Science Cheat Sheet NumPy Basics Learn Python for Data Science Interactively at www.DataCamp.com NumPy DataCamp Learn Python for Data Science Interactively The NumPy library is the core library for scientific computing in Python. It provides a high-performance multidimensional array object, and tools for working with these arrays. Python For Data Science Cheat Sheet NumPy Basics Learn Python for Data Science Interactively at www.DataCamp.com NumPy DataCamp Learn Python for Data Science Interactively The NumPy library is the core library for scienti c computing in Python. It provides a high-performance multidimensional array object, and tools for working with these arrays. This Python cheat sheet will guide you through variables and data types, Strings, Lists, to eventually land at the fundamental package for scientific computing with Python, Numpy. Python is the top dog when it comes to data science for now and in the foreseeable future. Knowledge of NumPy, one of its most powerful libraries is often a requirement for Data Scientists today. Use this cheat sheet as a guide in the beginning and come back to it when needed, and you’ll be well on your way to mastering the NumPy library.

  1. Python Data Types Cheat Sheet Pdf
  2. Best Python Cheat Sheet
  3. Python Data Types Cheat Sheet Answers
  4. Python Data Types Cheat Sheet Example
  5. Python Dictionary
Jump to:navigation, search

Numbers: integers and floats[edit]

  • Integers don't have a decimal place.
  • Floats have a decimal place.
  • Math mostly works the way it does on a calculator, and you can use parentheses to override the order of operations.

Math: addition, subtraction, multiplication[edit]

addition: 2 + 2
subtraction: 0 - 2
multiplication: 2 * 3

Math: division[edit]

Division always produces a float (i.e., a number that knows about the decimal place).

Types[edit]

Strings[edit]

  • Strings are bits of text, and contain characters like numbers, letters, whitespace, and punctuation.
  • String are surrounded by quotes.
  • Use triple-quotes ('') to create whitespace-preserving multi-line strings.

String concatenation[edit]

Printing strings[edit]

Types[edit]

Booleans[edit]

  • There are two booleans, True and False.
  • Use booleans to make decisions.
Types

Containment with 'in' and 'not in'[edit]

Equality[edit]

  • tests for equality
  • != tests for inequality
  • <, <=, >, and >= have the same meaning as in math class.

Use with if/else blocks[edit]

  • When Python encounters the if keyword, it evaluates the expression following the keyword and before the colon. If that expression is True, Python executes the code in the indented code block under the if line. If that expression is False, Python skips over the code block.

Types[edit]

Lists[edit]

Python
  • Use lists to store data where order matters.
  • Lists are indexed starting with 0.

List initialization[edit]

Python Data Types Cheat Sheet Pdf

Access and adding elements to a list[edit]

Best Python Cheat Sheet

Changing elements in a list[edit]

Slicing lists[edit]

Strings are a lot like lists[edit]

  • One big way in which strings are different from lists is that lists are mutable (you can change them), and strings are immutable (you can't change them). To 'change' a string you have to make a copy:
Python

Types[edit]

Dictionaries[edit]

Python Data Types Cheat Sheet Answers

Sheet

Python Data Types Cheat Sheet Example

  • Use dictionaries to store key/value pairs.
  • Dictionaries do not guarantee ordering.
  • A given key can only have one value, but multiple keys can have the same value.

Initialization[edit]

Python Data Types Cheat Sheet

Adding elements to a dictionary[edit]

Python Dictionary

Accessing elements of a dictionary[edit]

Changing elements of a dictionary[edit]

Types[edit]

Retrieved from 'https://wiki.communitydata.science/index.php?title=Python_data_types_cheat_sheet&oldid=82657'