~Variables & Data types:
It represents the kind of value that tells what operations can be
performed on a particular data. Since everything is an object in
Python programming, data types are actually classes and variables
are instance (object) of these classes.
#Assigning Single Values
character_name = "John"
print(character_name)
#Variables-consits of at least some sort of info inside them
print(type(character_name))
#Data types-tells us if the output is a string or integer or another
#form of data type such as the following:
#Floating Point(decimal)
#Character
#String
#Boolean
#Enumerated type
#Array
#Date
#Integer
character_age = "75" #This will be a string as I'm using ""
print(character_age)
print(type(character_age))
is_male = True #Boolean Value
print("Hi my name is " + character_name + ", I like to play basketball")
print("I am " + character_age + " years old, but, still enjoy playing this sport.")
charater_name1 = "Mike"
character_age1 = "75"
is_female = False #Boolean Value
print("His friend " + charater_name1 + " also enjoys playing basketball")
print("YET! Again he's also " + character_age1 + ".")
Boolean Value
The boolean gives us two paths either true or false, if the
password was wrong the computer will return false, however
if it is right then the computer will generate true
# Pyhton data types
# Integer
age = 18
# Float (AKA Floating point number)
current_balance = 51.28
# Boolean
is_tall = False # can be set to either True or False
# String
message = "Have a nice day"
# List
my_list = ["apples", 5, 7.3]
# Dictionary
my_dictionary = {'amount': 75}
# Tuple
coordinates = (40, 74) # can NOT be changed later
# Set
my_set = {5, 6, 3}
# What Are Variables In Python?
# A variable is a memory location where you store a value.
# The value that you have stored may change in the future according to the specifications
# A Variable in python is created as soon as a value is assigned to it.
# It does not need any additional commands to declare a variable in python.
# Variable Definition & Declaration
x = 10
# Variable is declared as the value 10 is assigned to it.
# Rules when declaring variable
# 1. The variable name cannot start with a number.
# 2. It can only start with a character or an underscore.
# 3. Variables in python are case sensitive.
# 4. They can only contain alpha-numeric characters and underscores.
# 5. No special characters are allowed.
# Data Types In Python
# INTEGERS: are used to represent whole number values.
x = 100
y = 124
# it will be the integer as long as the value is a whole number.
# To check the type of any variable data type, we can use the type() function.
# It will return the type of the mentioned variable data type.
# FLOAT data type: is used to represent decimal point values.
x = 10.25
y = 12.30
# COMPLEX NUMBERS: are used to represent imaginary values.
# Imaginary values are denoted with ‘j’ at the end of the number.
x = 10 + 5j
# BOOLEAN: is used for categorical output, since the output of
# boolean is either true or false.
num = 5 > 4
#num is the boolean variable
type(num)
#the output will be bool
print(num)
#this will print true.
# Strings: in python are used to represent unicode character values.
# Python does not have a character data type,
# a single character is also considered as a string.
# We denote or declare the string values inside single quotes or double
# quotes. To access the values in a string,
# we use the indexes and square brackets.
name = 'edureka'
name[2]
#this will give you the output as 'u'
# Strings are immutable in nature, which means you cannot change a string
# once replaced.
# LIST: is ordered and changeable, unlike strings.
# We can add duplicate values as well. To declare a list we use the
# square brackets.
mylist = [10,20,30,40,20,30, 'edureka']
# SETS: set is a collection which is unordered,
# it does not have any indexes as well.
# To declare a set in python we use the curly brackets.
myset = {10, 20 , 30 ,40, 50, 50}
# TUPLES: is a collection which is unchangeable or immutable
mytuple = (10,10,20,30,40,50)
# DICTIONARY: is just like any other collection array in python.
# But they have key value pairs
mydictionary = { 'python': 'data science', 'machine learning' : 'tensorflow' , 'artificial intelligence': 'keras'}
mydictionary['machine learning']
#this will give the output as 'tensorflow'
mydictionary.get('python')
#this serves the same purpose to access the value.
x = "You Rock!" #str
x = 69 #int
x = 69.9 #float
x = 1j #complex
x = ["red", "blue", "green"] #list
x = ("red", "blue", "green") #tuple
x = range(20) #range
x = {"name" : "Taylor", "age" : 35} #dict
x = {"red", "blue", "green"} #set
x = frozenset({"red", "blue", "chegreenrry"}) #frozenset
x = True #bool
x = b"You Rock!" #bytes
x = bytearray(10) #bytearray
x = memoryview(bytes(10)) #memoryview
x = None #NoneType