{"id":129,"date":"2026-08-03T13:06:38","date_gmt":"2026-08-03T13:06:38","guid":{"rendered":"https:\/\/pymedlab.com\/?p=129"},"modified":"2026-08-03T16:49:32","modified_gmt":"2026-08-03T16:49:32","slug":"python-basics","status":"publish","type":"post","link":"https:\/\/pymedlab.com\/ar\/python-basics\/","title":{"rendered":"Python Basics"},"content":{"rendered":"<p class=\"ext-animate--on wp-block-paragraph\"><strong>Lesson 1: Getting Started with Python<\/strong><\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\"><strong>Category:<\/strong> Python \u2192 Python Basics<\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\"><strong>Difficulty:<\/strong> Beginner<\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\"><strong>Estimated Reading Time:<\/strong> 8 minutes<\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\"><strong>Prerequisites:<\/strong> None<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity ext-animate--on\"\/>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\"><strong>Learning Objectives<\/strong><\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">By the end of this lesson, you will be able to:<\/p>\n\n\n\n<ul class=\"wp-block-list ext-animate--on\">\n<li class=\"ext-animate--on\">Understand what Python is and why it is widely used.<\/li>\n\n\n\n<li class=\"ext-animate--on\">Install Python on your computer.<\/li>\n\n\n\n<li class=\"ext-animate--on\">Launch the Python IDLE environment.<\/li>\n\n\n\n<li class=\"ext-animate--on\">Write and execute your first Python commands.<\/li>\n\n\n\n<li class=\"ext-animate--on\">Understand the difference between the Python Shell and Python scripts.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity ext-animate--on\"\/>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\"><strong>Introduction<\/strong><\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">Python is one of the world&#8217;s most popular programming languages because it is easy to learn, readable, and extremely powerful. It is widely used in scientific computing, artificial intelligence, machine learning, data science, and medical imaging.<\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">For medical physicists, radiologists, and imaging researchers, Python has become the standard programming language for analyzing DICOM images, processing CT and MRI scans, building AI models, and automating clinical workflows.<\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">In this lesson, you&#8217;ll install Python and become familiar with the Python Interactive Development and Learning Environment (IDLE), which is an excellent tool for beginners.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity ext-animate--on\"\/>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\"><strong>Why Learn Python for Medical Imaging?<\/strong><\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">Python is used in many medical imaging applications, including:<\/p>\n\n\n\n<ul class=\"wp-block-list ext-animate--on\">\n<li class=\"ext-animate--on\">Reading DICOM images<\/li>\n\n\n\n<li class=\"ext-animate--on\">Image processing<\/li>\n\n\n\n<li class=\"ext-animate--on\">Radiomics<\/li>\n\n\n\n<li class=\"ext-animate--on\">Machine learning<\/li>\n\n\n\n<li class=\"ext-animate--on\">Deep learning<\/li>\n\n\n\n<li class=\"ext-animate--on\">AI-assisted diagnosis<\/li>\n\n\n\n<li class=\"ext-animate--on\">Medical image visualization<\/li>\n<\/ul>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">Throughout PyMedLab, every tutorial will build upon the skills introduced here.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity ext-animate--on\"\/>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\"><strong>Step 1 \u2013 Installing Python<\/strong><\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">Visit the official Python website:<\/p>\n\n\n\n<figure class=\"wp-block-embed ext-animate--on\"><div class=\"wp-block-embed__wrapper\">\nhttps:\/\/www.python.org\/downloads\n<\/div><\/figure>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">Download the latest stable version of Python for your operating system.<\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">During installation on Windows, make sure you check:<\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">&#x2611; <em>Add Python to PATH<\/em><\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">before clicking <strong>Install Now<\/strong>.<\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">After installation, verify that Python is available by opening the Command Prompt and typing:<\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">python &#8211;version<\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">Example output:<\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">Python 3.14.0<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity ext-animate--on\"\/>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\"><strong>Step 2 \u2013 Starting IDLE<\/strong><\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">Python comes with a beginner-friendly programming environment called <strong>IDLE<\/strong>.<\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\"><strong>IDLE<\/strong> stands for:<\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\"><strong>Integrated Development and Learning Environment<\/strong><\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">To open IDLE on Windows:<\/p>\n\n\n\n<ol start=\"1\" class=\"wp-block-list ext-animate--on\">\n<li class=\"ext-animate--on\">Open the <strong>Start Menu<\/strong>.<\/li>\n\n\n\n<li class=\"ext-animate--on\">Search for <strong>IDLE<\/strong>.<\/li>\n\n\n\n<li class=\"ext-animate--on\">Click <strong>IDLE (Python 3.x)<\/strong>.<\/li>\n<\/ol>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">When IDLE starts, you&#8217;ll see the <strong>Python Shell<\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full ext-animate--on\"><img loading=\"lazy\" decoding=\"async\" width=\"683\" height=\"463\" src=\"https:\/\/pymedlab.com\/wp-content\/uploads\/2026\/08\/image-1.png\" alt=\"\" class=\"wp-image-130\" srcset=\"https:\/\/pymedlab.com\/wp-content\/uploads\/2026\/08\/image-1.png 683w, https:\/\/pymedlab.com\/wp-content\/uploads\/2026\/08\/image-1-300x203.png 300w, https:\/\/pymedlab.com\/wp-content\/uploads\/2026\/08\/image-1-18x12.png 18w\" sizes=\"auto, (max-width: 683px) 100vw, 683px\" \/><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity ext-animate--on\"\/>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\"><strong>Understanding the Python Shell<\/strong><\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">The Python Shell is an interactive environment where you can type Python commands and immediately see the results.<\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">For example:<\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">2 + 3<\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">Output:<\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">5<\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">Another example:<\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">Print (&#8220;Welcome to PyMedLab!&#8221;)<\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">Output:<\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">Welcome to PyMedLab!<\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">The Shell is useful for experimenting with small pieces of code before writing complete programs.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity ext-animate--on\"\/>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\"><strong>Writing Your First Program<\/strong><\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">Let&#8217;s write a simple program.<\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">In IDLE, click:<\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">File<\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">\u2193<\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">New File<\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">Type the following code:<\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">Print (&#8220;Hello, PyMedLab!&#8221;)<\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">Save the file as:<\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">hello.py<\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">Run it by selecting:<\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">Run<\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">\u2193<\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">Run Module<\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">Output:<\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">Hello, PyMedLab!<\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">Congratulations! You&#8217;ve written your first Python program.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity ext-animate--on\"\/>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\"><strong>Clinical Insight<\/strong><\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">Although &#8220;Hello World&#8221; is a simple example, the same workflow is used to develop software for medical imaging.<\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">Soon you&#8217;ll write programs that:<\/p>\n\n\n\n<ul class=\"wp-block-list ext-animate--on\">\n<li class=\"ext-animate--on\">Read CT images<\/li>\n\n\n\n<li class=\"ext-animate--on\">Display MRI slices<\/li>\n\n\n\n<li class=\"ext-animate--on\">Process DICOM files<\/li>\n\n\n\n<li class=\"ext-animate--on\">Build AI models<\/li>\n\n\n\n<li class=\"ext-animate--on\">Analyze radiomics features<\/li>\n<\/ul>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">Every advanced application begins with these fundamental steps.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity ext-animate--on\"\/>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\"><strong>Common Mistakes<\/strong><\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">New Python users often encounter a few common issues during installation and when running their first programs. Being aware of these mistakes can save you time and frustration.<\/p>\n\n\n\n<ul class=\"wp-block-list ext-animate--on\">\n<li class=\"ext-animate--on\"><strong>Forgetting to check &#8220;Add Python to PATH&#8221; <\/strong>during installation on Windows. If this option is not selected, you may not be able to run Python from the Command Prompt.<\/li>\n\n\n\n<li class=\"ext-animate--on\"><strong>Typing Python commands in the Command Prompt instead of the Python Shell. <\/strong>Remember that commands such as print(&#8220;Hello&#8221;) should be entered in the Python Shell or in a Python script, not directly in the operating system&#8217;s command prompt.<\/li>\n\n\n\n<li class=\"ext-animate--on\"><strong>Saving Python files without the .py extension. <\/strong>Python recognizes program files by their (.py) extension (for example, hello.py).<\/li>\n\n\n\n<li class=\"ext-animate--on\"><strong>Forgetting to save your script before running it. <\/strong>Always save your work before selecting Run \u2192 Run Module (F5) in IDLE to ensure that the latest version of your code is executed.<\/li>\n\n\n\n<li class=\"ext-animate--on\"><strong>Saving scripts in different folders. <\/strong>As a beginner, it is good practice to create a dedicated project folder for each lesson or project and save all related Python scripts, data files, and images in that folder. Keeping everything organized makes it easier to find your files and avoids problems with missing data or incorrect file paths.<\/li>\n\n\n\n<li class=\"ext-animate--on\"><strong>Best Practice<\/strong><\/li>\n<\/ul>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">For example, if you&#8217;re following the PyMedLab tutorials, you could organize your files like this:<\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">Python\/<\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">\u2502\u2500\u2500 Lesson01_Getting_Started\/<\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">\u2502&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; hello.py<\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">\u2502&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exercise1.py<\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">\u2502\u2500\u2500 Lesson02_Variables\/<\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">\u2502&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; variables.py<\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">\u2502\u2500\u2500 Lesson03_NumPy\/<\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">\u2502&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; numpy_arrays.py<\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">\u2502\u2500\u2500 Lesson04_DICOM\/<\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; read_dicom.py<\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CT_Image.dcm<\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">As you progress to medical imaging, you can keep each lesson self-contained. For example, a DICOM lesson might look like:<\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">Load_DICOM_Images\/<\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">\u2502\u2500\u2500 load_dicom.py<\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">\u2502\u2500\u2500 notebook. ipynb<\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">\u2502\u2500\u2500 CT_Image.dcm<\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">\u2502\u2500\u2500 output.png<\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">\u2502\u2500\u2500 README.md<\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">This organization makes your projects easier to manage, share, and upload to GitHub.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity ext-animate--on\"\/>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\"><strong>Exercises<\/strong><\/p>\n\n\n\n<ol start=\"1\" class=\"wp-block-list ext-animate--on\">\n<li class=\"ext-animate--on\">Install Python on your computer.<\/li>\n\n\n\n<li class=\"ext-animate--on\">Open IDLE.<\/li>\n\n\n\n<li class=\"ext-animate--on\">Calculate:<\/li>\n<\/ol>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">25 + 37<\/p>\n\n\n\n<ol start=\"4\" class=\"wp-block-list ext-animate--on\">\n<li class=\"ext-animate--on\">Print your name.<\/li>\n<\/ol>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">Print (&#8220;Your Name&#8221;)<\/p>\n\n\n\n<ol start=\"5\" class=\"wp-block-list ext-animate--on\">\n<li class=\"ext-animate--on\">Create a file called:<\/li>\n<\/ol>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">first_program.py<\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">and print your favorite programming language.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity ext-animate--on\"\/>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\"><strong>Summary<\/strong><\/p>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">In this lesson, you learned how to:<\/p>\n\n\n\n<ul class=\"wp-block-list ext-animate--on\">\n<li class=\"ext-animate--on\">Install Python<\/li>\n\n\n\n<li class=\"ext-animate--on\">Open IDLE<\/li>\n\n\n\n<li class=\"ext-animate--on\">Use the Python Shell<\/li>\n\n\n\n<li class=\"ext-animate--on\">Create your first Python script<\/li>\n\n\n\n<li class=\"ext-animate--on\">Run a Python program<\/li>\n<\/ul>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\">These skills provide the foundation for all future lessons in PyMedLab.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity ext-animate--on\"\/>\n\n\n\n<p class=\"ext-animate--on wp-block-paragraph\"><strong>Next Lesson<\/strong><\/p>","protected":false},"excerpt":{"rendered":"<p>Lesson 1: Getting Started with Python Category: Python \u2192 Python Basics Difficulty: Beginner Estimated Reading Time: 8 minutes Prerequisites: None Learning Objectives By the end of this lesson, you will be able to: Introduction Python is one of the world&#8217;s most popular programming languages because it is easy to learn, readable, and extremely powerful. It [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"footnotes":""},"categories":[20],"tags":[],"class_list":["post-129","post","type-post","status-publish","format-standard","hentry","category-getting-started-python"],"_links":{"self":[{"href":"https:\/\/pymedlab.com\/ar\/wp-json\/wp\/v2\/posts\/129","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pymedlab.com\/ar\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pymedlab.com\/ar\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pymedlab.com\/ar\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pymedlab.com\/ar\/wp-json\/wp\/v2\/comments?post=129"}],"version-history":[{"count":1,"href":"https:\/\/pymedlab.com\/ar\/wp-json\/wp\/v2\/posts\/129\/revisions"}],"predecessor-version":[{"id":131,"href":"https:\/\/pymedlab.com\/ar\/wp-json\/wp\/v2\/posts\/129\/revisions\/131"}],"wp:attachment":[{"href":"https:\/\/pymedlab.com\/ar\/wp-json\/wp\/v2\/media?parent=129"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pymedlab.com\/ar\/wp-json\/wp\/v2\/categories?post=129"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pymedlab.com\/ar\/wp-json\/wp\/v2\/tags?post=129"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}