Self-teaching how to code with Python, part 5: Overview Of Python Objects Types

4년 전

When coding with Python we realize that the fundamental idea is creating objects and apply operations (addition, concatenation, etc) on those objects. Objects are essentially pieces of memory with some data and operations associated with them, objects can be built-in by default in Python or they can be created using Python or other languages tools.

In a broader perspective, Python programs can be broken down into modules, statements, expressions, and objects. Thus a Python program contains at least one module, which in times contains statements that are built with expressions and those expressions create and process objects.

Built-in Objects

In lower level languages, implementing data structures, managing memory allocation, implement search and access routines, and so on, are really time-consuming tasks. Python provides a powerful set of built-in objects. Thus, coding objects implementations is not necessary unless some special properties are required.

Let's review some advantages of using built-in objects:

  • Simple task can be carried out entirely with built-in objects
  • More complex objects are usually implemented on top of built-in objects such as list (collections) and dictionaries (search tables).
  • Built-in objects have already optimized data structure algorithms that are implemented in C for achieving greater speed
  • Python's built-in object are fully standardized.

Object types. Numbers

Numbers in Python range from integers (those without fractional part), floating-points numbers (numbers with a decimal point in them), and some more complex types (fixed-precision decimals -pi, e, etc; rational fractions, complex numbers with imaginary parts, and some more).

Ordinary mathematical operations are supported as well. The plus sign (+) performs addition, a start (*) is used for multiplication, two stars are used for exponentiation (**). For now, this will suffice to describe this object type, more advanced tools are available by importing some modules shipped with Python or using third-party modules. Since their application is more specific, they will be covered in other posts.

Object types. Strings

Strings are a positionally ordered collection of bytes generally used to record textual information or some other random data. They are the simplest versions of an array of one-character string called which are called Sequences.

Strings support operations that involve positional ordering between elements. Let's review some examples:

>>> S = "string"
>>> len(S)      # This will show the length of the string
>>> S[0]        # This will show the first element of the string from left to right
>>> S[3]        # This will show the fourth element of the string from left to right 
>>> S[-1]       # This will show the first element of the string from right to left

The first position is enumerated with the number 0. Also, negative indexes are added to the string size, and the element on that position is then printed. One of the cool features of Python is that its syntax is really general. If a function is expecting us to input some value, we could use a literal, a variable, or any other equivalent expression. For instance, we can fetch the last item of a string in the above example by typing either of the following expressions.

>>> S = "string"
>>> S[-1]
>>> S[len(S)-1]

More on strings and other Python objects will be covered in the next part of the series

Previous work

Basic Concepts. Part 1
Whaleshares Link
Steemit Link
Basic Concepts. Part 2
Whaleshares Link
Steemit Link
Program designing. Part 3
Whaleshares Link
Steemit Link
Program designing. Part 4
Whaleshares Link
Steemit Link


  • Learning Python, Mark Lutz. O'Reilly, 4th edition
  • Python Para Todos, Raúl González Duque. (Licensed under Creative Commons Attribution ShareAlike 2.0)
  • Python 3 for absolute beginners, Tim Hall and J-P Stacey. Apress
  • Python for Software Design, Allen B. Downey. Cambridge University Press

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  trending

Congratulations @joelsegovia! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

Award for the number of posts published

Click on the badge to view your Board of Honor.
If you no longer want to receive notifications, reply to this comment with the word STOP

To support your work, I also upvoted your post!

Do not miss the last post from @steemitboard:

SteemitBoard - Witness Update

Support SteemitBoard's project! Vote for its witness and get one more award!

You got a 6.51% upvote from @dailyupvotes courtesy of @joelsegovia!

This post has received a $33.33 % upvote from @siditech thanks to: @joelsegovia.
Here's a banana! banana-small.png

Congratulations! This post has been upvoted from the communal account, @minnowsupport, by joelsegovia from the Minnow Support Project. It's a witness project run by aggroed, ausbitbank, teamsteem, someguy123, neoxian, followbtcnews, and netuoso. The goal is to help Steemit grow by supporting Minnows. Please find us at the Peace, Abundance, and Liberty Network (PALnet) Discord Channel. It's a completely public and open space to all members of the Steemit community who voluntarily choose to be there.

If you would like to delegate to the Minnow Support Project you can do so by clicking on the following links: 50SP, 100SP, 250SP, 500SP, 1000SP, 5000SP.
Be sure to leave at least 50SP undelegated on your account.

Sneaky Ninja Attack! You have just been defended with a 16.05% upvote!
I was summoned by @joelsegovia. I have done their bidding and now I will vanish...

A portion of the proceeds from your bid was used in support of @youarehope and @tarc.

Abuse Policy
How to use Sneaky Ninja
How it works

You just received a 9.52% upvote from @honestbot, courtesy of @joelsegovia!

Great post!
Thanks for tasting the eden!

Great post! You've earned a 29.41% upvote from @dolphinbot
Join the DolphinBot Team for Daily Payouts in Steem! Click here:

You got a 7.67% upvote from @joeparys! Thank you for your support of our services. To continue your support, please follow and delegate Steem power to @joeparys for daily steem and steem dollar payouts!

You got a 19.56% upvote from @moneymatchgaming courtesy of @joelsegovia! Please consider upvoting this post to help support the MMG Competitive Gaming Community.

You got a 21.74% upvote from @steembloggers courtesy of @joelsegovia!