Ad Code

Responsive Advertisement

Ticker

6/recent/ticker-posts

10 Advantages Of Learn Python And How You Can Make Full Use Of It.

#Artificial Intelligence-AI-PHYTON

o      Variables and Simple  Data  Types:-

 

·        What Really Happens When You Run hello_world.py.

 

(a)    Let’s take a closer look at what Python does when you run hello_world.py. As it turns out, Python does a fair amount of work, even when it runs a simple program: print ("Hello Python world!") When you run this code, you should see this output:

(i)     Hello Python world!

(b)   When you run the file hello_world.py, the ending.py indicates that the file is a Python program. Your editor then runs the file through the Python interpreter, which reads through the program and determines what each word in the program means. For example, when the interpreter sees the word print followed by parentheses, it prints to the screen whatever is inside the parentheses. As you write your programs, your editor highlights different parts of your program in different ways. For example, it recognizes that print () is the name of a function and displays that word in one color. It recognizes that "Hello Python world!" is not Python code and displays that phrase in a different color. This feature is called syntax highlighting and is quite useful as you start to write your own programs.

 

o  Variables

(a)    Let’s try using a variable in hello_world.py. Add a new line at the beginning of the file, and modify the second line: message = "Hello Python world!" print(message) Run this program to see what happens. You should see the same output you saw previously:

(b)   Hello Python world! We’ve added a variable named message.

(c)    Every variable is connected to a value, which is the information associated with that variable. In this case, the value is the "Hello Python world!" text. Adding a variable makes a little more work for the Python Class interpreter.

(d)   When it processes the first line, it associates the variable message with the "Hello Python world!" text. When it reaches the second line, it prints the value associated with the message to the screen. Let’s expand on this program by modifying hello_world.py to print a second message.

o  Add a blank line to hello_world.py, and then add two new lines of code: message = "Hello Python world!" print(message) message = "Hello Python Crash Course world!" print(message) Now when you run hello_world.py, you should see two lines of output: Hello Python world!

LEARN PYTHON



 

o  Naming and Using Variables

 

§  When you’re using variables in Python, you need to adhere to a few rules and guidelines. Breaking some of these rules will cause errors; another guide [1]lines just help you write code that’s easier to read and understand. Be sure to keep the following variable rules in mind:

§  Variable names can contain only letters, numbers, and underscores. They can start with a letter or an underscore, but not with a number. For instance, you can call a variable message_1 but not 1_message. • Spaces are not allowed in variable names, but underscores can be used to separate words in variable names. For example, a greeting message works, but a greeting message will cause errors. • Avoid using Python keywords and function names as variable names; that is, do not use words that Python has reserved for a particular pro[1]grammatical purpose, such as the word print. ITS

#pythonclass

Post a Comment

0 Comments