Python Data Types

A variable can hold values of different data types. While declaring a variable we do not need to define the data type.

Standard Data Types

Python has five standard data types,

Numbers

Number data type stores numeric values from, python support three types of numerical types,

  • Integer
  • float
  • complex

Integer

Integer data type stores whole values, integer may be positive, negative or zero(-∞, 0, +∞). We can find the type of object using type() function.

Example:

A = 57
print(A, "This is an example for Integer Data type")
print("The type of object is:", type(A))

Output:

57 This is an example for Integer Data type
The type of object is: <class 'int'>

float

Float data type is used to store floating-point numbers. We can use float() function to return floating-point numbers.

Example:

A = 35.7
B = float(12)
print(A, "This is an example for Integer Data type")
print("The type of object is:", type(A))
print(B)

Output:

35.7 This is an example for Integer Data type
The type of object is: <class 'float'>
12.0

Complex

A complex value contain a real part and a imaginary part, we can access the real part by using real() function and imaginary pat can be accessed by imag() function. complex() function is used to import complex values. To use complex() function we need to import cmath library.

Example:

A = 5
B = 7
D = complex(A, B)
print(D)
print(type(D))
print("The Real part is:", D.real)
print("The Imaginary part is:", D.imag)

Output:

(5+7j)
<class 'complex'>
The Real part is: 5.0
The Imaginary part is: 7.0

String

A String in python can be defined as single quotes, double quotes or in triple quotes. We can concatenate two strings using + operator. To repeat a string values more than one times * operator is used.

Example:

A = "Neural Beast"
B = "Always Deliver More than Expected"
print(type(A))
print(A + "", B)
print(A * 2)

Output:

<class 'str'>
Neural Beast Always Deliver More than Expected
Neural BeastNeural Beast

List

A list can be created using square brackets[] and the values inside is separated with comma. We can change the values in python.

Example:

mylist = ["keyboard", "mouse", "monitor"]
print(type(mylist))
print(mylist)

Output:

<class 'list'>
['keyboard', 'mouse', 'monitor']

Tuple

Tuple is just like list, to create a tuple rounded brackets() are used, to separate vales comma is used. We cannot change the values inside a tuple.

Example:

mytuple = ("keyboard", "mouse", "monitor")
print(type(mytuple))
print(mytuple)

Output:

<class 'tuple'>
('keyboard', 'mouse', 'monitor')

Dictionary

Python Dictionary is an unordered collection. A Dictionary is created with curly brackets{}, it has a keys and values. To assign a key with a value single colon “:” is used. To separate a key and value comma is used. We can change the values in a dictionary.

Example:

dict = {"Name" : "Neural Beast", "Tutorial" : "Python Tutorial"}
print(type(dict))
print(dict)

Output:

<class 'dict'>
{'Name': 'Neural Beast', 'Tutorial': 'Python Tutorial'}

More Reading

Post navigation

24 Comments

  • Many thanks for your post. I would like to write my opinion that the expense of car insurance varies greatly from one policy to another, due to the fact there are so many different facets which bring about the overall cost. For example, the make and model of the auto will have a huge bearing on the price. A reliable older family car will have a lower priced premium compared to a flashy expensive car.

  • I’ve learned several important things via your post. I would also like to convey that there may be a situation where you will have a loan and never need a co-signer such as a National Student Support Loan. However, if you are getting a borrowing arrangement through a standard creditor then you need to be willing to have a co-signer ready to enable you to. The lenders will probably base that decision using a few elements but the most significant will be your credit history. There are some financial institutions that will furthermore look at your work history and decide based on this but in many cases it will be based on on your ranking.

  • My coder is trying to convince me to move to .net from PHP. I have always disliked the idea because of the expenses. But he’s tryiong none the less. I’ve been using WordPress on various websites for about a year and am anxious about switching to another platform. I have heard excellent things about blogengine.net. Is there a way I can import all my wordpress posts into it? Any help would be greatly appreciated!

  • hi!,I like your writing so much! share we communicate more about your post on AOL? I require a specialist on this area to solve my problem. Maybe that’s you! Looking forward to see you.

  • One thing I’d really like to say is always that car insurance cancellations is a feared experience so if you’re doing the suitable things being a driver you won’t get one. A number of people do get the notice that they’ve been officially dumped by their insurance company and several have to struggle to get added insurance from a cancellation. Inexpensive auto insurance rates usually are hard to get following a cancellation. Understanding the main reasons with regard to auto insurance cancelling can help motorists prevent completely losing in one of the most important privileges out there. Thanks for the concepts shared via your blog.

  • Great ?I should certainly pronounce, impressed with your website. I had no trouble navigating through all tabs and related info ended up being truly simple to do to access. I recently found what I hoped for before you know it at all. Quite unusual. Is likely to appreciate it for those who add forums or something, web site theme . a tones way for your client to communicate. Nice task..

  • I have noticed that online diploma is getting preferred because accomplishing your degree online has become a popular solution for many people. Quite a few people have certainly not had a possibility to attend a normal college or university yet seek the improved earning possibilities and a better job that a Bachelor’s Degree grants. Still other people might have a college degree in one course but would choose to pursue something they now possess an interest in.

  • I am also commenting to make you know what a awesome discovery my friend’s princess undergone studying your web page. She picked up a wide variety of details, not to mention what it is like to have a great coaching mood to get many others with ease understand a variety of multifaceted topics. You really surpassed people’s desires. Many thanks for giving such practical, trustworthy, edifying and unique tips on the topic to Janet.

  • Thank you for any other informative site. The place else may I am getting that kind of info written in such an ideal means? I have a project that I’m just now running on, and I’ve been at the glance out for such information.

  • Thanks for the sensible critique. Me & my neighbor were just preparing to do some research on this. We got a grab a book from our local library but I think I learned more clear from this post. I’m very glad to see such great information being shared freely out there.

  • There are some fascinating cut-off dates on this article but I don抰 know if I see all of them center to heart. There is some validity however I will take hold opinion until I look into it further. Good article , thanks and we would like more! Added to FeedBurner as well

  • Well composed articles llike yours renews my faith in today’s writers.You’ve written information I can finally agree
    on and also use.Manyy thanks for sharing.

Leave a Reply

Your email address will not be published. Required fields are marked *