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

how to specify variable type in python

x = "20"
y = 5.7
z = 90
print(type(x))
print(type(y))
print(type(z))
a = int(x)
b = str(y)
c = float(z)
print(type(a))
print(type(b))
print(type(c))
Comment

variables and data types in python

# 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 Variables and Data Types

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

python variable type

myVar = ""

myType = type(myVar)
# Output: <class 'str'>
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 :: python scroll 
Python :: dict pop with index python 
Python :: cython could not creat pyd file no such file or directory 
Python :: pandas join non-unique 
Python :: horney 
Python :: tkinter label abstand nach oben 
Python :: dbscan clustering of latitudes and longitudes 
Python :: Assigning X and y using .iloc index 
Python :: How to pass a data frame as parameter to a SQL query in Python? 
Python :: numpy array values not updateing 
Python :: connect two mathod to the same button in pyq5 
Python :: git ignore everything but python files 
Python :: readme python convert to pdf 
Python :: python how to request query string korean encode 
Python :: access matrix value opencv 
Python :: crear ondas segun musica python 
Python :: python amino acid dictionary 
Python :: create series with number intervals 
Python :: python turn seconds into zulu time 
Python :: fibonacci numbers function python print 
Python :: Can I convert python code to C++? 
Python :: np.ma.filled 
Python :: how to make a square multicolor square spiral python 
Python :: who is agada nathan 
Python :: multiply two list in python using lambda 
Python :: comment interpreter tuple python avec valeur unique 
Python :: python sys replace text 
Python :: python anywhere just says hello from flask 
Python :: Python find permutations of operators between each digit in a given string of digits will result in a particular answer 
Python :: python bitcoin prices 
ADD CONTENT
Topic
Content
Source link
Name
3+3 =