Learn Basic Python Easily for Beginners — Basic Syntax: Variable And Data Type

Som ay
3 min readDec 21, 2022

--

Photo by James Harrison on Unsplash

Python is one of the favorite programming languages ​​used by data scientists to analyze data. Python is a programming language that is included in the category of high-level programming language, because it is easy for humans to read and write. In addition, Python is also intended for general-purpose programming, which can be used for various kinds of problems, such as developing web, mobile, data science applications, and others. Python coding is easy for beginners to learn and understand.

Variable in python

Variables are mutable data stores, meaning their values ​​can change. Variables in python have the format of writing variable_name = <value>. Variables can contain text or numbers. There are several rules for writing variables, namely:

  1. Variable names may begin with a letter or underscore (_) and cannot begin with a number (0–9), for example: myname, _name
  2. Characters in variables are sensitive, meaning that uppercase and lowercase letters have different meanings.
  3. variable names cannot use keywords that are already in python

The Following is an example of using variables in python coding

name = 'roby'
full_name = 'roby dosantos'
number1 = '1'
number2 = '2

Data type in python

If previously it has been explained that a variable is a place for storing data, then the type of data stored in this variable is called a data type. There are several types of data types, namely:

  1. type null: used to store an empty value, declared with None
  2. boolean type: used to store a truth value (True or False)
  3. numeric type: used to store data in the form of numbers, represented by int (integer) and float (real number)
  4. text type: used to store text data, declared with str.

List data type in python

Sequence data type is a type of data type that is used to store a set of data in an organized manner. There are two forms of sequence data types, namely List and Tuple. The list data type begins with an opening bracket ( [ ), separates each element with a comma ( , ) and closes with a closing bracket ( ] ). The list data type is mutable, meaning that each element in the list can be changed. The elements of the list have an index that starts at 0 and continues to increase by one value until the last element of the list. The following is an example of using the list data type

example_list = [1,2,'try','5','eat']

print(example_list[0]
print(example_list)

Tuple data type

The next sequence data type is the tuple data type, which is the data type used to store a set of data. Writing this tuple data type begins with an opening bracket ( ( ), separates each element using a comma ( , ) and closes with a closing bracket ( ) ). If the list data type is mutable, then this tuple data type is immutable, meaning that the elements in this tuple data type cannot be changed after their declaration. The following is an example of using the tuple data type in python

example_tuple = ('january','February','March','April')
print(exmple_tuple)
print(example_tuple[0])

--

--