Data Types in Python with explanation

 Python Data Types with explanation





Data Types in Python:

·         It represents what type of data is stored in a variable.

Example:




There are two types of data types

1.       Built-in Data Type

2.       User Define Data Type

Keywords in Python:

  • Keywords are the reserved words in Python. We cannot use a keyword as the variable name, function name, or any other identifier.
  • Here's a list of all keywords in Python Programming





Note: Only three keywords starting with capital letters False, None, and True

In order to get the content/help from python itself:- print(help())






Number data types - store numeric values. They are immutable data types, which means that changing the value of a number data type results in a newly allocated object.

Collection data types are also called sequence data types.

Note: No double data type available in python


Int (signed integers) − they are often called just integers or int, are positive or negative whole numbers with no decimal point.

The default value is 0.







Float (floating point real values) − Also called floats, they represent real numbers and are written with a decimal point dividing the integer and fractional parts.

The default value is 0.0






Complex (complex numbers) − are of the form a + bJ., where a and b are floats and J (or j) represents the square root of -1 (which is an imaginary number). The real part of the number is a, and the imaginary part is b. Complex numbers are not used much in Python programming.

The default value is 0j








Boolean:-  Boolean values are the two constant objects False and True.

The default value is False





Note: -
All default value is returns 0(False)








String: -  Strings are amongst the most popular types in Python. It is a collection of characters; we can create them simply by enclosing characters in quotes. Python treats single quotes the same as double-quotes.

The default value for the string is “ “,’ ‘






Question:-How to declare a string?














·         Anything that will be placed under ‘  ‘& “ “ will be considered as string data type.

‘_’ define data types in python

·         If the string is spinning into more than one line use a triple single quote or a triple-double quote.








Note:- In python, the string data types are immutable. Which means a string value cannot be updated.















print(help())

print(dir(str))


 


List: - The list is the most versatile data type available in Python which can be written as a list of comma-separated values (items) between square brackets. The important thing about a list is that items in a list need not be of the same type.

Default value is [], list()

Creating a list is as simple as putting different comma-separated values between square brackets.





Similar to string indices, list indices start at 0, and lists can be sliced, concatenated, and so on.

Accessing Values in Lists

To access values in lists, use the square brackets for slicing along with the index or indices to obtain the value available at that index.


















 Set: - A Set is an unordered collection data type that is iterable, mutable, and has no duplicate elements. In Python, sets are written with curly brackets.

Note: Sets are unordered, so the items will appear in random order.
























·         Set values will be embedded in {}

·         Set will allow only the unique values (In case if there are any duplicates then those duplicate values should be removed)

·         Insertion order is not maintained

·         Set will not support indexing


 Tupple:- A tuple is a sequence of immutable Python objects. Tuples are sequences, just like lists. The differences between tuples and lists are, the tuples cannot be changed, unlike lists and tuples that use parentheses, whereas lists use square brackets.

Creating a tuple is as simple as putting different comma-separated values. Optionally you can put these comma-separated values between parentheses also. 






The empty tuple is written as two parentheses containing nothing, to write a tuple containing a single value you have to include a comma, even though there is only one value.









Like string indices, tuple indices start at 0, and they can be sliced, concatenated, and so on.


Del:- It will delete all the specified data.














Modifications in Tuple:

























































Dictionary: - Each key is separated from its value by a colon (:), the items are separated by commas, and the whole thing is enclosed in curly braces. An empty dictionary without any items is written with just two curly braces, like this: {}.

Keys are unique within a dictionary while values may not be. The values of a dictionary can be of any type, but the keys must be of an immutable data type such as strings, numbers, or tuples.

















Comments

Popular Post

Root Cause Analysis in Testing | Easy way to explain in interview about RCA

Agile Testing Interview Questions and Answers | Easy way to explain the Agile Testing Interview Questions.

Static and Non Static Method in Python | Class Method in Python

How to Run Python Code in IDLE

OOPS in python | Object Oriented Programming Languages and Systems | Static and Non Static in Python

Python IDEs and Code Editor | PyCharm

What is the difference between client-side validation and server-side validation?

Operators in Python and Types of Operators in Python

How to Download Python ?