<!DOCTYPE html>
	<html lang="vi" xmlns="http://www.w3.org/1999/xhtml" prefix="og: http://ogp.me/ns#">
	<head>
<title>&#91;Python Cơ Bản&#93; Phần 5&#x3A; Tìm hiểu chương trình Python đầu tiên</title>
<meta name="description" content="&#91;Python Cơ Bản&#93; Phần 5&#x3A; Tìm hiểu chương trình Python đầu tiên - Savefile - Tin Tức -...">
<meta name="author" content="TỔ TIN HỌC TRƯỜNG THPT ĐỖ CÔNG TƯỜNG">
<meta name="copyright" content="TỔ TIN HỌC TRƯỜNG THPT ĐỖ CÔNG TƯỜNG [webmaster@tinhocdct.xyz]">
<meta name="robots" content="index, archive, follow, noodp">
<meta name="googlebot" content="index,archive,follow,noodp">
<meta name="msnbot" content="all,index,follow">
<meta name="generator" content="NukeViet v4.0">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta property="og:title" content="&#91;Python Cơ Bản&#93; Phần 5&#x3A; Tìm hiểu chương trình Python đầu tiên">
<meta property="og:type" content="website">
<meta property="og:description" content="Savefile - Tin Tức - https&#x3A;&#x002F;&#x002F;tinhocdct.xyz&#x002F;savefile&#x002F;hoat-dong-chuyen-mon&#x002F;python-co-ban-phan-5-tim-hieu-chuong-trinh-python-dau-tien-120.html">
<meta property="og:site_name" content="TỔ TIN HỌC TRƯỜNG THPT ĐỖ CÔNG TƯỜNG">
<meta property="og:url" content="https://tinhocdct.xyz/hoat-dong-chuyen-mon/python-co-ban-phan-5-tim-hieu-chuong-trinh-python-dau-tien-120.html">
<link rel="shortcut icon" href="https://tinhocdct.xyz/favicon.ico">
<link rel="canonical" href="https://tinhocdct.xyz/hoat-dong-chuyen-mon/python-co-ban-phan-5-tim-hieu-chuong-trinh-python-dau-tien-120.html">
<link rel="alternate" href="https://tinhocdct.xyz/rss/" title="Tin Tức" type="application/rss+xml">
<link rel="alternate" href="https://tinhocdct.xyz/rss/tin-tuc/" title="Tin Tức - TIN TỨC" type="application/rss+xml">
<link rel="alternate" href="https://tinhocdct.xyz/rss/thong-cao-bao-chi/" title="Tin Tức - THÔNG BÁO" type="application/rss+xml">
<link rel="alternate" href="https://tinhocdct.xyz/rss/ban-tin-noi-bo/" title="Tin Tức - BẢN TIN NỘI BỘ" type="application/rss+xml">
<link rel="alternate" href="https://tinhocdct.xyz/rss/tin-cong-nghe/" title="Tin Tức - CÔNG NGHỆ - KHOA HỌC" type="application/rss+xml">
<link rel="alternate" href="https://tinhocdct.xyz/rss/thu-thuat/" title="Tin Tức - THỦ THUẬT" type="application/rss+xml">
<link rel="alternate" href="https://tinhocdct.xyz/rss/tien-ich/" title="Tin Tức - TIỆN ÍCH" type="application/rss+xml">
<link rel="alternate" href="https://tinhocdct.xyz/rss/ai/" title="Tin Tức - AI" type="application/rss+xml">
<link rel="alternate" href="https://tinhocdct.xyz/rss/khoa-hoc/" title="Tin Tức - KHOA HỌC" type="application/rss+xml">
<link rel="alternate" href="https://tinhocdct.xyz/rss/hoat-dong-chuyen-mon/" title="Tin Tức - HOẠT ĐỘNG CHUYÊN MÔN" type="application/rss+xml">
<link rel="alternate" href="https://tinhocdct.xyz/rss/hoat-dong-cong-doan/" title="Tin Tức - CÔNG ĐOÀN" type="application/rss+xml">
<link rel="alternate" href="https://tinhocdct.xyz/rss/hoat-dong-doan-the/" title="Tin Tức - ĐOÀN THỂ" type="application/rss+xml">
<link rel="alternate" href="https://tinhocdct.xyz/rss/tuyen-sinh-huong-nghiep/" title="Tin Tức - TUYỂN SINH - HƯỚNG NGHIỆP" type="application/rss+xml">
<link rel="alternate" href="https://tinhocdct.xyz/rss/tuyen-sinh-2025/" title="Tin Tức - TUYỂN SINH 2025" type="application/rss+xml">
<link rel="alternate" href="https://tinhocdct.xyz/rss/lich-cong-tac-tuan/" title="Tin Tức - Lịch công tác tuần" type="application/rss+xml">
<link rel="preload" as="script" href="https://tinhocdct.xyz/assets/js/jquery/jquery.min.js">
<link rel="preload" as="script" href="https://tinhocdct.xyz/assets/js/language/vi.js">
<link rel="preload" as="script" href="https://tinhocdct.xyz/assets/js/global.js">
<link rel="preload" as="script" href="https://tinhocdct.xyz/themes/default/js/news.js">
<link rel="preload" as="script" href="https://tinhocdct.xyz/themes/default/js/main.js">
<link rel="preload" as="script" href="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1816161148536198">
<link rel="preload" as="script" href="https://tinhocdct.xyz/themes/default/js/bootstrap.min.js">
<link rel="StyleSheet" href="https://tinhocdct.xyz/assets/css/font-awesome.min.css">
<link rel="StyleSheet" href="https://tinhocdct.xyz/themes/default/css/bootstrap.non-responsive.css">
<link rel="StyleSheet" href="https://tinhocdct.xyz/themes/default/css/style.css">
<link rel="StyleSheet" href="https://tinhocdct.xyz/themes/default/css/style.non-responsive.css">
<link rel="StyleSheet" href="https://tinhocdct.xyz/themes/default/css/news.css">
<style>
	body{background: #fff;}
</style>
	</head>
	<body>
<div id="print">
	<div id="hd_print">
		<h2 class="pull-left">TỔ TIN HỌC TRƯỜNG THPT ĐỖ CÔNG TƯỜNG</h2>
		<p class="pull-right"><a title="TỔ TIN HỌC TRƯỜNG THPT ĐỖ CÔNG TƯỜNG" href="https://tinhocdct.xyz/">https://tinhocdct.xyz</a></p>
	</div>
	<div class="clear"></div>
	<hr />
	<div id="content">
		<h1>&#91;Python Cơ Bản&#93; Phần 5&#x3A; Tìm hiểu chương trình Python đầu tiên</h1>
		<ul class="list-inline">
			<li>Thứ ba - 25/05/2021 05:53</li>
			<li class="hidden-print txtrequired"><em class="fa fa-print">&nbsp;</em><a title="In ra" href="javascript:;" onclick="window.print()">In ra</a></li>
			<li class="hidden-print txtrequired"><em class="fa fa-power-off">&nbsp;</em><a title="Đóng cửa sổ này" href="javascript:;" onclick="window.close()">Đóng cửa sổ này</a></li>
		</ul>
		<div class="clear"></div>
		<div id="hometext">
			Trong bài viết này chúng ta cùng tìm hiểu một chương trình Python đơn giản để có cái nhìn rõ hơn một chút về Python, trước khi bắt đầu học về các thành phần chính của ngôn ngữ lập trình này nhé.
		</div>
				<div class="imghome">
			<img alt="Python" src="https://tinhocdct.xyz/uploads/news/2021_05/hinh-1.png" width="460" class="img-thumbnail" />
		</div>
		<div class="clear"></div>
		<div id="bodytext" class="clearfix">
			<p>Thông thường, khi bắt đầu học bất kỳ một ngôn ngữ lập trình nào từ Pascal, C cho đến HTML, chương trình đầu tiên mà gần như mọi giáo viên đều hướng dẫn chúng ta viết là &quot;Hello, World!&quot; hay &quot;Xin chào!&quot;. Chương trình đơn giản này sẽ in ra màn hình một lời chào.</p>

<p>Như đã đề cập ở những bài viết trước, Python là ngôn ngữ lập trình rất dễ để học, và việc tạo ra chương trình &quot;Hello, World!&quot; lại càng đơn giản, bạn chỉ cần viết dòng code&nbsp;<code>print(&quot;Hello, World!&quot;)</code>.</p>

<p>Vì thế, chúng ta sẽ đi tìm hiểu một chương trình khác, cũng đơn giản thôi, để bạn hiểu thêm một chút về ngôn ngữ lập trình này. Tạm đặt tên nó là Thêm hai số:</p>

<pre id="pre0">
<code># Them hai so va in tong
num1 = 6
num2 = 9
sum = num1+num2
print(sum) </code></pre>

<p><img alt="Chương trình Thêm hai số trên Python" data-i="0" data-src="https://st.quantrimang.com/photos/image/2017/09/26/chuong-trinh-python-them-hai-so.PNG" data-was-processed="true" height="229" src="https://st.quantrimang.com/photos/image/2017/09/26/chuong-trinh-python-them-hai-so.PNG" width="650" /></p>

<p><strong>Đoạn code trên sẽ làm gì?</strong></p>

<p>Dòng 1:&nbsp;<code># Them hai so va in tong</code></p>

<p>Bất kỳ dòng code nào trong Python bắt đầu với dấu # sẽ là chú thích, bình luận. Nó được sử dụng để mô tả về đoạn code bên dưới dùng để làm gì. Điều này sẽ giúp cho những lập trình viên khác, người đọc code, hiểu code rõ hơn. Những dòng bắt đầu với # sẽ được các trình biên dịch code và trình phiên dịch code bỏ qua.</p>

<p>Dòng 2:&nbsp;<code>num1 = 6</code></p>

<p><code>num1&nbsp;</code>ở đây là biến, bạn có thể lưu trữ giá trị trong biến và trong trường hợp này,&nbsp;<code>num1</code>&nbsp;lưu giá trị 6.</p>

<p>Dòng 3:&nbsp;<code>num2 = 9</code></p>

<p>Tương tự như trên, 9 được lưu trữ trong&nbsp;<code>num2</code>.</p>

<p>Dòng 4:&nbsp;<code>sum = num1+num2</code></p>

<p>Tổng của biến&nbsp;<code>num1</code>&nbsp;và&nbsp;<code>num2</code>&nbsp;được lưu trữ trong một biến khác là&nbsp;<code>sum</code>.</p>

<p>Dòng 5:&nbsp;<code>print(sum)</code></p>

<p>Hàm&nbsp;<code>print()</code>&nbsp;in đầu ra trên màn hình. Trong trường hợp này nó sẽ in kết quả 15 trên màn hình, sau khi bạn nhấn F5.</p>

<p><img alt="Kết quả chạy code Python thêm hai số" data-i="1" data-src="https://st.quantrimang.com/photos/image/2017/09/26/ket-qua-chay-code-python-them-hai-so.PNG" data-was-processed="true" height="222" src="https://st.quantrimang.com/photos/image/2017/09/26/ket-qua-chay-code-python-them-hai-so.PNG" width="650" /></p>

<p><strong>Một vài lưu ý nhỏ:</strong></p>

<p>Để biểu diễn một câu lệnh trong Python, ta sử dụng dòng mới (Enter). Việc sử dụng dấu ; ở cuối câu lệnh là tùy chọn (không bắt buộc như trên C/C++, JavaScripts hay PHP). Trên thực tế, bạn nên bỏ qua những dấu ; này ở cuối câu lệnh trong Python.</p>

<p>Thay vì dấu ngoặc {}, thụt lề được sử dụng để biểu diễn một khối lệnh. Ví dụ:</p>

<pre id="pre1">
<code>this_is_MS_Office:

    this_is_Word:

        this-is-Word-document

    this_is_Excel:

        this-is-Excel-spreadsheet</code></pre>
&nbsp;

<p>Cùng chờ xem trong bài tiếp theo chúng ta sẽ biết thêm kiến thức gì trong Python nhé!<br  />
<em>Phần sau:</em>&nbsp;<a href="http://tinhocdct.xyz/hoat-dong-chuyen-mon/python-co-ban-phan-6-cac-kieu-du-lieu-trong-python-119.html" target="_blank">&#91;Python Cơ Bản&#93; Phần 6:&nbsp;Các kiểu dữ liệu trong Python</a><br  />
<em>Phần trước:</em>&nbsp;<a href="http://tinhocdct.xyz/hoat-dong-chuyen-mon/python-co-ban-phan-4-cach-viet-lenh-thut-le-va-chu-thich-trong-python-118.html" target="_blank">&#91;Python Cơ Bản&#93; Phần 4:&nbsp;Cách viết lệnh, thụt lề và chú thích trong Python</a></p>
		</div>
				<div id="author">
						<p>
				<strong>Tác giả bài viết:</strong>
				Thanh Sơn
			</p>
						<p>
				<strong>Nguồn tin:</strong>
				quantrimang.com
			</p>
		</div>
	</div>
	<div id="footer" class="clearfix">
		<div id="url">
			<strong>URL của bản tin này: </strong><a href="https://tinhocdct.xyz/hoat-dong-chuyen-mon/python-co-ban-phan-5-tim-hieu-chuong-trinh-python-dau-tien-120.html" title="&#91;Python Cơ Bản&#93; Phần 5&#x3A; Tìm hiểu chương trình Python đầu tiên">https://tinhocdct.xyz/hoat-dong-chuyen-mon/python-co-ban-phan-5-tim-hieu-chuong-trinh-python-dau-tien-120.html</a>

		</div>
		<div class="clear"></div>
		<div class="copyright">
			&copy; TỔ TIN HỌC TRƯỜNG THPT ĐỖ CÔNG TƯỜNG
		</div>
		<div id="contact">
			<a href="mailto:webmaster@tinhocdct.xyz">webmaster@tinhocdct.xyz</a>
		</div>
	</div>
</div>
        <div id="timeoutsess" class="chromeframe">
            Bạn đã không sử dụng Site, <a onclick="timeoutsesscancel();" href="https://tinhocdct.xyz/#">Bấm vào đây để duy trì trạng thái đăng nhập</a>. Thời gian chờ: <span id="secField"> 60 </span> giây
        </div>
        <div id="openidResult" class="nv-alert" style="display:none"></div>
        <div id="openidBt" data-result="" data-redirect=""></div>
<script src="https://tinhocdct.xyz/assets/js/jquery/jquery.min.js"></script>
<script>var nv_base_siteurl="/",nv_lang_data="vi",nv_lang_interface="vi",nv_name_variable="nv",nv_fc_variable="op",nv_lang_variable="language",nv_module_name="news",nv_func_name="savefile",nv_is_user=0, nv_my_ofs=-4,nv_my_abbr="EDT",nv_cookie_prefix="nv4",nv_check_pass_mstime=1738000,nv_area_admin=0,nv_safemode=0,theme_responsive=0,nv_is_recaptcha=0;</script>
<script src="https://tinhocdct.xyz/assets/js/language/vi.js"></script>
<script src="https://tinhocdct.xyz/assets/js/global.js"></script>
<script src="https://tinhocdct.xyz/themes/default/js/news.js"></script>
<script src="https://tinhocdct.xyz/themes/default/js/main.js"></script>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1816161148536198"
     crossorigin="anonymous"></script>
<script src="https://tinhocdct.xyz/themes/default/js/bootstrap.min.js"></script>
</body>
</html>