What are the different data types in Python?

Python Datatypes:
  • Boolean
  • Numbers
  • Strings
  • Lists
  • Tuples
  • Sets
  • Dictionaries
Boolean:
  • Booleans are either true or false.
  • Python has 2 constants named True and False which can be used to assign a boolean value directly.
  • In certain places ( like if statements ), Python expects an expression to a boolean value, these places are called boolean contexts.
Numbers:
  • Python supports both int and floating point numbers.
Tuples:
  • A tuple is an immutable list, it means a tuple can't be changed in a way once it's created.
  • A tuple is defined in the same way as a list, except that the whole set of an element is enclosed in the parenthesis instead of square brackets.
  • Similarities with the list :
    • Tuples have a defined order i.e. Indices are 0 based, so the first element of a non-empty tuple is always a_tuple[ 0 ].
    • Negative indices count from the end of the tuple.
    • Slicing works too, when we slice a list we get a new list. When we slice a tuple, we get a new tuple.
  • The difference with lists:
    • Tuple can't be changed. In technical terms, tuples are immutable in practical terms, tuples have no methods that would allow to change them. List have methods like append() , extend(), insert() , remove() and pop().
    • Tuples are faster than lists. In CPython, tuples are stored in a single block of memory, so creating a new tuple involves at worst a single call to allocate memory. Lists are allocated in two blocks: the fixed one with all the Python object information and a variable sized block for the data. That's part of the reason why creating a tuple is faster, but it probably also explains the slight difference in indexing speed as there is one fewer pointer to follow.
    • Tuples make code safer since they are "write-protect".
Sets :
  • A set is an unordered "bag" of unique values.
  • A single set can contain values of any immutable datatype.
  • Once we have two sets, we can do standard operations like union, intersection and set difference.






Comments

  1. You truly did more than visitors’ expectations. Thank you for rendering
    these helpful, trusted, edifying and also cool thoughts on the topic to
    Kate.

    Selenium Training in Chennai

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. I believe there are many more pleasurable opportunities ahead for individuals that looked at your site.
    http://www.besanttechnologies.com/training-courses/other-training-courses/devops-training-institute-in-chennai

    ReplyDelete
    Replies
    1. Existing without the answers to the difficulties you’ve sorted out through this guide is a critical case, as well as the kind which could have badly affected my entire career if I had not discovered your website. DevOps Training in Bangalore

      Delete
  4. Thanks a lot very much for the high quality and results-oriented help. I won’t think twice to endorse your blog post to anybody who wants and needs support about this area.

    AWS training in bangalore

    ReplyDelete
  5. Besant Technologies has been NO.1 & Best Software Training Institute offering 100% Guaranteed JOB Placements, Cost-Effective, Quality & Real time Training courses on Software Testing (Manual & Automation tools), Digital Marketing (SEO, PPC, SMO), Data Warehousing tools (Informatica 9.5, OBIEE 11g, Qlikview, Cognos BI & TM1, Microstrategy, DataStage), IBM Websphere, Weblogic, PHP & Mysql, Oracle SOA , Core .NET (Asp.net, c#, vb, ado.net) and Advanced .NET (WCF,WPF,Silver light, Linq, websockets), and JAVA training facility in Bangalore. AWS Training in Bangalore

    ReplyDelete
  6. Those guidelines additionally worked to become a good way to recognize that other people online have the identical fervor like mine to grasp great deal more around this condition.

    Selenium Training in Chennai

    Selenium Training in Porur

    ReplyDelete
  7. Thanks for sharing this valuable and interesting article with smart content..keep updating. Duplicate Payment Review
    Audit Artificial Intelligence

    ReplyDelete
  8. Hey, would you mind if I share your blog with my twitter group? There’s a lot of folks that I think would enjoy your content. Please let me know. Thank you.
    AWS Training in Chennai
    Data Science Training in Chennai
    Python Training in Chennai

    ReplyDelete

Post a Comment

Popular posts from this blog

What is composite key?

What is __repr__ function?