JoseTusabe com All right Reserved
Happy birthday Arya Sofia Copy
April 9, 2020
JOSETUSABE COM ALL RIGHT RESERVED
Variable and Types 2 More example – Python – Beginner 101 Copy
April 9, 2020

Variable and Types 2 More example – Python – Beginner 101 Copy

JOSETUSABE COM ALL RIGHT RESERVED

JOSETUSABE COM ALL RIGHT RESERVED

LearnPython

What is a variable?

A variable is a reserved memory location to store values. In other words, the word that you are using for a variable it is store in Python and it gives data to a computer for processing.

All the values in Python has a Datatype. There are several data types in Python, to mention some of them, Numbers, List, Tuple, Strings, Dictionary, etc. a Variable can be asingned by with any name provide by the programmer. Example: aa, abc, ate, name, abed, etc.

 

#            New in JoseTusabe WEB Learn the basic of Python
#                   Example Code - JoseTusabe.com
#                        What is a Variable?
#                        What are the data types in python?
#                        Give an example for each item  mentioned above.
#                        Jose Luis Encarnacion
# What is a Variable?
# A variable is a reserved memory location to store values. In other words, the word that you are using
# for a variable it is store in Python and it gives data to a computer for processing.
# All the values in Python has a Datatype. There are several data types in Python, to mention some of
# them, Numbers, List, Tuple, Strings, Dictionary, etc. a Variable can be assigned by with any name provide
# by the programmer. Example: aa, abc, ate, name, abed, etc.
#
#
# Now let see some examples of a variable and data types in Python.
# Example 1 a Variable
# In this case i will assigned to the letter "a", a value and then i will print it.
print()  # This print statement is just to give 1 space, this is optional, but for me the print code
#          it look more clean
a = "Hello, My name is Jose L Encarnacion"
print(a)
# I assigned to "a", a string value called "Hello, My name is Jose L Encarnacion" this is the value of "a"
# Now let see another example, now i will give "b" a number value
print ()
b = 20 # "20" is the value of "b"
# Now to see the value of "b" I have to use the print statement.
print (b)
# Note: if i use the same variable again will overwrite the old one and use the new value for that variable
# Example
b = "Is not longer 20"
print (b)
# In the print console you can see it prints the first value witch is "20"
# but from now on  when i print it again the value for "b" it will be "Is not longer 20" which is now the value of "b"
print ()
print (b)
###############################################################
# What are data type in python.
# Data type are, numeric, list, tuple, set, string, range, dictionary etc.
# Numeric type: int, float, complex and bool
# Example 1
ts = 2.5
print (type(ts)) # output float
print ()
ts2 = 5
print (type(ts2)) # output int
print ()
print (a)
print (type(a)) # This output str.
print ()
# Example of complex
jts1 = 21+33j # Note: this J is represented by a square of -1
print ()
print (jts1) # output is (21+33j)
# now i will see the type
print (type(jts1)) # output <class 'complex'>
print ()
############################################################
# A list is a data structure in Python that is a mutable, or changeable, ordered sequence of elements.
# Each element or value that is inside of a list is called an item. Just as strings are defined as
# characters between quotes, lists are defined by having values between square brackets [ ]
# Example of list in Python
ts_list = [12, 22, 23, 33, 54, 55, 4]
print ()
print (ts_list)
# Now to see what type of list it is:
print ()
print (type(ts_list)) # Output <class 'list'>
# What is a set in Python
# Sets in Python. A Set is an unordered collection data type that is iterable,
# mutable and has no duplicate elements. Python's set class represents the mathematical notion of a set.
# This is based on a data structure known as a hash table.
print ()
# Example of sets
ts_set = {23, 34,33, 44, 44, 12, 44}
print (ts_set) # Output is {33, 34, 44, 12, 23}
# there is not duplicate value
print (type(ts_set)) # Output is <class 'set'>
print ()
# What is tuple
# A tuple is a sequence of immutable Python objects. Tuples are sequences, just like lists. The differences between
# tuples and lists are, the tuples cannot be changed unlike lists and tuples use parentheses,
# whereas lists use square brackets. Creating a tuple is as simple as putting different
# comma-separated values.
# Example of tuple.
ts_tuple = (12, 22, 33, 43, 55)
print (ts_tuple)
print (type(ts_tuple)) # Output is <class 'tuple'>
print ()
# Example of a string
ts_str = "My name is Jose L"
print (ts_str)
# Now to see what type is:
print () # This print statement is just to give a space
print (type(ts_str)) # Output will be <class 'str'>
print ()
########################################################## Range ##########################
# he range() function is used to generate a sequence of numbers over time. At its simplest,
# it accepts an integer and returns a range object (a type of iterable). In Python 2, the range()
# returns a list which is not very efficient to handle large data
# Example of range
r = list(range(21)) #This will make a list of numbres from 0 to 20, this is because it start from 0 but it not
# Include the last number wich is 21
# Output of this will be [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
print (r)
w = list(range(3, 34, 6)) # This will print a list of numbers starting from 3, up to 34, up  by 6
# This output will be -- [3, 9, 15, 21, 27, 33]
print (w)
#########################################################
# What is Dictionary in Python
# Dictionary in Python is an unordered collection of data values, used to store data values like a map,
# which unlike other Data Types that hold only single value as an element, Dictionary holds key:value pair.
# Key value is provided in the dictionary to make it more optimized.
# Example of a dictionary - In this example i will give 3 people the phone they are using.
print ()
ts_dictionary = {"Jose" : "samsung", "Luis" : "Iphone", "Miguel" : "OnePlus"}
print (ts_dictionary) # Output {'Jose': 'samsung', 'Luis': 'Iphone', 'Miguel': 'OnePlus'}
print ()
print (type(ts_dictionary)) # Output is <class 'dict'>
# If i only want to see the key:
print (ts_dictionary.keys()) # output ---- dict_keys(['Jose', 'Luis', 'Miguel'])
print (ts_dictionary.values())  # output ----- dict_values(['samsung', 'Iphone', 'OnePlus'])
# Now if i just what to get only one value of the dictionary I have to specify the key. Example
print ()
print (ts_dictionary["Jose"]) # OutPut --- samsung
print ()
print (ts_dictionary["Luis"]) # Output is --- Iphone
# I also can use the get function
# Example
print ()
print (ts_dictionary.get("Miguel")) #Output will be -- OnePlus
print ()
#Thank you, that will be all for now. Any Question please letme know.

Copy the code

...Python Console

Terminal to test the code, delete the existing code and paste the new one and run it.
 

What is Python? Executive Summary

              Python is an interpreted, object-oriented, high-level programming language with dynamic semantics. Its high-level built in data structures, combined with dynamic typing and dynamic binding, make it very attractive for Rapid Application Development, as well as for use as a scripting or glue language to connect existing components together. Python's simple, easy to learn syntax emphasizes readability and therefore reduces the cost of program maintenance. Python supports modules and packages, which encourages program modularity and code reuse. The Python interpreter and the extensive standard library are available in source or binary form without charge for all major platforms, and can be freely distributed.

-

              Often, programmers fall in love with Python because of the increased productivity it provides. Since there is no compilation step, the edit-test-debug cycle is incredibly fast. Debugging Python programs is easy: a bug or bad input will never cause a segmentation fault. Instead, when the interpreter discovers an error, it raises an exception. When the program doesn't catch the exception, the interpreter prints a stack trace. A source level debugger allows inspection of local and global variables, evaluation of arbitrary expressions, setting breakpoints, stepping through the code a line at a time, and so on. The debugger is written in Python itself, testifying to Python's introspective power. On the other hand, often the quickest way to debug a program is to add a few print statements to the source: the fast edit-test-debug cycle makes this simple approach very effective.

-

            See also some comparisons between Python and other languages.

Book Appointment

 
old
old

Leave a Reply

JOSETUSABE.COM ALL RIGHT RESERVED

                    ALL RIGHT RESERVED

avatar
  Subscribe  
Notify of