-
Notifications
You must be signed in to change notification settings - Fork 0
/
chapter_1.html
96 lines (80 loc) · 3.87 KB
/
chapter_1.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
Chapter 1. Python - Basic Syntax
<div class="container">
<div class="divider"></div>
<p>The Python language has many similarities to Perl, C, and Java. However, there are some definite differences between the languages.</p>
<h5>First Python Program</h5>
<p>Let us execute programs in different modes of programming.</p>
<h6>Interactive Mode Programming</h6>
<p>Invoking the interpreter without passing a script file as a parameter brings up the following prompt −</p>
<div class="row">
<div class="card-panel grey lighten-5 z-depth-1">
<div class="row valign-wrapper">
<div class="col s12">
<p>$ python <br>
Python 2.4.3 (#1, Nov 11 2010, 13:34:43) <br>
[GCC 4.1.2 20080704 (Red Hat 4.1.2-48)] on linux2 <br>
Type "help", "copyright", "credits" or "license" for more information. <br>
>>></p>
</div>
</div>
</div>
</div>
<p>Type the following text at the Python prompt and press the Enter −</p>
<div class="row">
<div class="card-panel grey lighten-5 z-depth-1">
<div class="row valign-wrapper">
<div class="col s12">
<p>>>> print "Hello, Python!"</p>
</div>
</div>
</div>
</div>
<p>If you are running new version of Python, then you would need to use print statement with parenthesis as in <b>print ("Hello, Python!");</b>. However in Python version 2.4.3, this produces the following result −</p>
<div class="row">
<div class="card-panel grey lighten-5 z-depth-1">
<div class="row valign-wrapper">
<div class="col s12">
<p>Hello, Python!</p>
</div>
</div>
</div>
</div>
<div class="divider"></div>
<h6>Script Mode Programming</h6>
<p>Invoking the interpreter with a script parameter begins execution of the script and continues until the script is finished. When the script is finished, the interpreter is no longer active.
Let us write a simple Python program in a script. Python files have extension .py. Type the following source code in a test.py file −</p>
<div class="row">
<div class="card-panel grey lighten-5 z-depth-1">
<div class="row valign-wrapper">
<div class="col s12">
<p>print "Hello, Python!"</p>
</div>
</div>
</div>
</div>
<p>We assume that you have Python interpreter set in PATH variable. Now, try to run this program as follows −</p>
<div class="row">
<div class="card-panel grey lighten-5 z-depth-1">
<div class="row valign-wrapper">
<div class="col s12">
<p>$ python test.py</p>
</div>
</div>
</div>
</div>
<p>This produces the following result −</p>
<div class="row">
<div class="card-panel grey lighten-5 z-depth-1">
<div class="row valign-wrapper">
<div class="col s12">
<p>Hello, Python!</p>
</div>
</div>
</div>
</div>
<div class="divider"></div>
<div class="row"></div>
<div class="video-container">
<iframe width="560" height="315" src="https://www.youtube.com/embed/AGnECmJFA9U" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div>
</div>