Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

variables and data types in python

~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
Comment

python data types


Text Type:	str
Numeric Types:	int, float, complex
Sequence Types:	list, tuple, range
Mapping Type:	dict
Set Types:	set, frozenset
Boolean Type:	bool
Binary Types:	bytes, bytearray, memoryview
None Type:	NoneType
Comment

python data types

# 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}
Comment

python data types

# Float
average_tutorial_rating = 4.01
# Integer
age = 20
# Boolean
tutorials_are_good = True # True or False
# arrays/lists
numbers = [1, 2, 3]
Comment

python data types

# 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.
Comment

python data types

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
Comment

Python Variables and Data Types

name = "Paul"
age = "43"
print(" Hello " + name + " You are " + age)
Comment

variable types in python

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
~AppDataLocalTemp/ipykernel_12148/2794355031.py in <module>
----> 1 x4 = [x1, x2, x3]

NameError: name 'x1' is not defined
Comment

PREVIOUS NEXT
Code Example
Python :: BaseSSHTunnelForwarderError: Could not establish session to SSH gateway 
Python :: python write into file at position 
Python :: .lift tkinter 
Python :: Check and Install appropriate ChromeDriver Version for Selenium Using Python 
Python :: python np get indices where value 
Python :: python linear regression 
Python :: try catch python with open 
Python :: power in python 
Python :: how to remove an element from dictionary using his value python 
Python :: Python program to find uncommon words from two Strings 
Python :: python get line of exception 
Python :: pairwise function python 
Python :: super in django manager 
Python :: optimize images using pillow 
Python :: python convert list of lists of strings to int 
Python :: different dataframe name with for loop 
Python :: pyinstaller pymssql 
Python :: python programm zu exe 
Python :: Group by a column, count sum of other columns 
Python :: histogram chart plotly 
Python :: python how to drop columns from dataframe 
Python :: python merge strings 
Python :: logical operators python 
Python :: python dataframe calculate difference between columns 
Python :: merge keep left index 
Python :: how to remove a list of numbers from a list in python 
Python :: continue and break in python 
Python :: python single line function 
Python :: pyqt set focus 
Python :: how to create a button using tkinter 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =