GithubHelp home page GithubHelp logo

Data Types on Python

Numbers

  • Integer : Int, or integer, is a whole number, positive or negative, without decimals, of unlimited length.
  • Float : Float, or "floating point number" is a number, positive or negative, containing one or more decimals.
  • Complex : Complex numbers are written with a "j" as the imaginary part. Used for advanced math and engineering, similar to floats but with an imaginary component.

String

  • Strings are sequences of characters used for representing text or data.
  • Strings in python are surrounded by either single quotation marks (' '), or double quotation marks(" ").

Boolean

When you compare two values, the expression is evaluated and Python returns the Boolean answer. You can evaluate any expression in Python, and get one of two answers, True or False.

List

  • Lists are used to store multiple items in a single variable.
  • Lists are created using square brackets []
  • Lists can contain members of the same or different types
  • List items are ordered, changeable, and allow duplicate values.
  • List items are indexed, Index start from [0]

    List Methods

  • append() : Adds an element at the end of the list.
  • extend() : Add the elements of a list (or any iterable), to the end of the current list.
  • insert() : Adds an element at the specified position.
  • remove() : Removes the item with the specified value.
  • pop() : Removes the element at the specified position. If you do not specify the index, the pop() method removes the last item.
  • del () : The del keyword also removes the specified index.
  • count() : Returns the number of elements with the specified value.
  • index() : Returns the index of the first element with the specified value.
  • sort() : Sorts the list ascending, by default. To sort descending, use the keyword argument reverse = True.
  • reverse() : Reverses the order of the list

Tuple

  • Tuples are used to store multiple items in a single variable.

  • Tuple items are ordered, unchangeable, and allow duplicate values.

  • Tuples are written with round brackets( ).

  • Tuple items are indexed, Index start from [0].

    Tuple Methods

  • count() : Returns the number of times a specified value occurs in a tuple.

  • index() : Searches the tuple for a specified value and returns the position of where it was found

Set

  • Sets are used to store multiple items in a single variable.

  • Set items are unordered, unchangeable, unindexed and do not allow duplicate values.

  • Set items are unchangeable, but can remove items and add new items.

  • Sets are written with curly brackets{ }.

    Set Methods

  • add() : Adds an element to the set.

  • intersection() : Returns a set, that is the intersection of two other sets.

  • pop() : Removes an element from the set.

  • remove() : Removes the specified element.

  • union(): Return a set containing the union of sets.

Dictionaries

  • Dictionaries are used to store data values in key:value pairs.
  • Dictionary items are ordered, changeable, and does not allow duplicates.
  • Dictionary items are presented in key:value pairs, and can be referred to by using the key name.
  • Dictionaries are written with curly brackets { }, and have keys and values.

Length

len() : To determine how many items a set has, use the len() function.

Python Conditions and If Else Statements

Python has usual logic conditions from math :

  • Equals: a == b
  • Not Equals: a != b
  • Less than: a < b
  • Less than or equal to: a <= b
  • Greater than: a > b
  • Greater than or equal to: a >= b

An "if statement" is written by using the if keyword.

Elif

The elif keyword is Python's way of saying "if the previous conditions were not true, then try this condition".

Else

The else keyword catches anything which isn't caught by the preceding conditions.

For Loop

This is less like the for keyword in other programming languages, and works more like an iterator method as found in other object-orientated programming languages. With the for loop we can execute a set of statements, once for each item in a list, tuple, set etc.

The for loop does not require an indexing variable to set beforehand.

pritaaa's Projects

python-part-2 icon python-part-2

List Of Contents : Break, Continue, While Loops, List Comprehension, Functions

python-part-3 icon python-part-3

In the past week, we've dived into essential Python programming topics related to data manipulation: NumPy and Pandas

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.