GS Tech Info
NOTE: There are a few but true information is available.
The different - different types of data are called datatypes in programming(python). There are many datatypes in python.
int is a datatype in python which is used to store numbers in a variable. A interger will be positive, negative or zero. python's int has no maximum or minimum value like other programming languages, means you can store extermely large or small interger. Example:
1a = 719 # "a" is a variable which contains "719" as an integer.
2b = -786 # "b" is a variable which contains "-786" as an interger.
3
4c, d = 15, 0 # "c" contains "15" and "d" contains "0".
5
float is a datatype in python which is used to store floating point numbers (decimal point numbers) in a variable. It is almost same as int but it can store numbers with decimal point. Example:
1a = 1.2
2b = -8.9
3c = 0.0
4
str (string) is a datatype in python which is used to store strings in a variable. Means sting is datatype with can store anything including alphabets, numbers, characteres etc. A string is a immutable, means once a string is created it cannot be changed. when you are trying to change a string it will be create a new string in memory.
It represents a sequence of characters enclosed within either single quotes ('), double quotes ("), or triple quotes (''' or """).
Example:
a = "Hello"
Where.
Their are many way to create a string.
a = 'Hello World'
You can generate a string including double quates like this:
a = 'Hello' World'
if you want to add a single quate in a string than you need to create a string with double quates, otherwise this will through an error.
a = "Hello World"
You can generate a string including single quate like this:
a = "Hello' World"
if you want to add a double quate in a string than you need to create a string with single quates, otherwise this will through an error.
a = '''Hello world this is my string. Hello world this is my string. Hello world this is my string. Hello world this is my string. Hello world this is my string. Hello world this is my string. '''
In the above methods you cannot create a string in multiply lines.
The multi-line string is only allowed in triple quates no matter it is single to double.
1a = 'Hello world'
2b = "Hello World"
3c = 'Hello" world'
4d = "Hello' World"
5e = '''Hello World
6 this is a "multi-line" string'''
7f = """Hello World
8 this is a 'multi-line' string"""
9
bool is a datatype in python which is used to store truth value in a variable. The truth value is in the form of True or False.
1a = True
2b = False
3
list is a datatype in python which is used to store multiple types of data in a single variable. A list is ordered, mutable, and Heterogeneous.. Square brackets are used to create a list.
1a = ["ABC", 719, True, 12.95]
A list can contains another list called nested list.
1a = ["ABC", [12, 854]]
you can access this list's data using indexing.
1a = ["ABC", 719] # this list contains two elements first is "ABC"
2as a string and second is 719 as a int.
3
4# you can access this data by using:
5# a[0] # which means you want to access the first
6element of list contains by variable "a".
7
8# use print function
9print(a[0]) # this will print "ABC".
10print(a[1]) # this will print 719.
11
A list can contains another list called nested list.
You can access these element by using indexing of indexing.
1a = ["ABC", [12, 854]]
2print(a[1][0]) # it will print 12.
3print(a[1][1]) # it will print 854.
4
Tuple is a datatype in python which is ordered, indexed, and immutable. it can store different - different types of data, it is almost same as list but it is immutable and list is mutable.
Once a tuple is created you cannot modify it's elements such as add, remove, or change.
A tuple is enclosed with round brackes.
Example:
1a = (12, "ABC")
A set is a datatype in python which is unordered, unchangeable, and unindexed. it can store different-different types of data, it is almost same as list or tuple, with minner differences.
A set is enclosed with curly-braceses.
Example:
1a = {719, "GS"}