Python Variables and Data Types - Python Introduction

Published December 11, 2020

Python tutorial

 

GETTING STARTED WITH PYTHON (I)

Like we all know all programming languages come with their own syntax and semantics just like all spoken languages. English has its own way of greeting, Indian has its own, Nigerian has its own way and so do other languages. If I say Namaste, I am greeted in Hindi, If I say Good morning I am greeted in English, and so on. The Only thing that connects these languages together is the message I am passing across which is greeting.

Going by the established paradigm above, various programming has the same syntax(meaning) but a different structure(semantics), which means all programming languages can give us the same result.

Firstly, let’s introduce ourselves to Data types in Python. For us to be able to speak a language, we have to first know the basics of the language like letters, sentence formation, communication, and others. For us to be able to write an efficient python program, we first need to understand the Data types in Python.

What we know as of now is 

What is Python? 

Python History 

Features of Python

 

VARIABLES AND DATA TYPES IN PYTHON

A variable is a characteristic for a value. It can be assigned a name, you can use it to refer to it later in the program

By the value assigned to a variable, the interpreter decides its data type. We can always store a different type in a variable

In every language, there will a rule to assign the name to a variable.

Python also having some rules to assign the names to a variable.

 

Python Variables Naming Rules

  • Python variables must begin with a letter(A-Z/a-z) or an underscore(_)
  • Other letters can be a letters(A-Z/a-z), underscores(_), and numbers(0-9)
  • Python is case-sensitive, Which means Name and name are two different identifiers
  • Reserved words (keywords) cannot be used as identifier names

 

Data Types

Let’s look deeper into what these data types look like, data types are just the various information we play along with in order for our program to efficiently run and will give us the desired result.

Data types are numbers, alphabet, objects, and so on. Because Python is not our regular spoken languages but interpreted high-level programming language(close to what human being can understand), it has its own ways of recognizing all these data types, let's look at it from python view;

Int

Because it’s a programming language,  there is no way we won’t play around with numbers. Int is a numeric data type(number) that represents the whole number, for example, 0, 1, 2, 3, and so on…

Float

Like we have decimals and whole numbers, so do we have float and int. Float is another numeric data type that accepts a dot extension number like our decimal numbers for example 0.1, 1.3, 3.5, and so on

String

Just like when we want to make sentences, we have to write them in letters. The string is the enabler that helps us to write and make sentences in python, always abbreviated as str, for example, “I am a software developer” will be seen as a string in python.

Sequence

The sequence is a data type in python that acts more like a container, it can contain more than one data type, usually, we iterate through a list in python, we will buttress on it when we started playing around on python, four major data types under this, we have list, tuple, set and dictionary.

We have others like function, module, class, and quite a few others which when we get to where they are to be used, will make more sense and sound appealing to our development journey.

 

Lists

A list is a collection of values. Remember, it may contain different types of values.

To define a list, we must put values separated with commas in square brackets. You don’t need to declare a type for a list either

 

Dictionaries

A dictionary holds key-value pairs. It should be declare inside curly braces.

Key and values are separated by (:) and pair will be separated by (,)

>>> student={'name':'Python','rollno':22}

 

 

Thank You for reading, We are on our journey to writing our python program

 

Article Contributed By :
https://www.rrtutors.com/site_assets/profile/assets/img/avataaars.svg

610 Views