-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpython_programming.html
More file actions
150 lines (139 loc) · 8.6 KB
/
python_programming.html
File metadata and controls
150 lines (139 loc) · 8.6 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<!DOCTYPE HTML>
<!--
Phantom by HTML5 UP
html5up.net | @ajlkn
Free for personal and commercial use under the CCA 3.0 license (html5up.net/license)
-->
<html>
<head>
<title>Python Programming</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
<link rel="stylesheet" href="assets/css/main.css" />
<noscript><link rel="stylesheet" href="assets/css/noscript.css" /></noscript>
</head>
<body class="is-preload">
<!-- Wrapper -->
<div id="wrapper">
<!-- Header -->
<header id="header">
<div class="inner">
<!-- Logo -->
<a href="index.html" class="logo">
<span class="symbol"><img src="images/NeuroNestLogo.png" alt="NeuroNest Logo" /></span><span class="title">NeuroNest</span>
</a>
<!-- Nav -->
<nav>
<ul>
<li><a href="#menu">Menu</a></li>
</ul>
</nav>
</div>
</header>
<!-- Menu -->
<nav id="menu">
<h2>Menu</h2>
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="resource_menu.html">Resources</a></li>
<li><a href="https://sopkoc.wixsite.com/neuronest/forum">Ask a Question</a></li>
<li><a href="https://sopkoc.wixsite.com/neuronest/about">About NeuroNest</a></li>
<li><a href="https://sopkoc.wixsite.com/neuronest/contact">Contact</a></li>
</ul>
</nav>
<!-- Main -->
<div id="main">
<div class="inner">
<h1 id="python-programming">Introduction to Programming in Python</h1>
<p>This section provides a foundational understanding of Python programming, covering essential topics like coding style, debugging, testing, and control flow. Whether you're a beginner or looking to solidify your programming practices, the resources here will guide you through the core aspects of writing effective Python code.</p>
<h2 id="1-python-coding-style">1. Python Coding Style</h2>
<p>Adhering to a consistent coding style is crucial for writing readable and maintainable code. Python’s official style guide, <a href="https://peps.python.org/pep-0008/">PEP 8</a>, provides comprehensive guidelines on how to format your code. Following PEP 8 ensures that your code is clean, organized, and consistent with the wider Python community.</p>
<ul>
<li><strong>Indentation</strong>: Use 4 spaces per indentation level.</li>
<li><strong>Line Length</strong>: Limit all lines to a maximum of 79 characters.</li>
<li><strong>Imports</strong>: Imports should be on separate lines, and grouped in the order of standard library imports, related third-party imports, and local application/library-specific imports.</li>
</ul>
<p>For additional tools to enforce style conventions and check for common errors, consider using <a href="https://pypi.org/project/flake8-pytest-style/">flake8</a>.</p>
<h2 id="2-debugging-and-testing">2. Debugging and Testing</h2>
<p>Writing robust code involves rigorous debugging and testing. Python offers several built-in and third-party tools to help ensure your code runs correctly.</p>
<ul>
<li><p><strong>Debugging</strong>: Use the built-in <code>pdb</code> module to step through your code and inspect variables in real-time. The <a href="https://docs.python.org/3/tutorial/errors.html">Python documentation</a> offers a detailed guide on using <code>pdb</code>.</p>
</li>
<li><p><strong>Testing</strong>: The <code>unittest</code> module is Python’s built-in testing framework, while <a href="https://docs.pytest.org/en/stable/">pytest</a> is a popular third-party tool that simplifies writing and running tests.</p>
</li>
</ul>
<h2 id="3-control-flow">3. Control Flow</h2>
<p>Understanding control flow is fundamental to writing effective programs. Control flow structures allow you to dictate the execution of statements based on conditions.</p>
<ul>
<li><p><strong>Conditional Statements</strong>: The <code>if</code>, <code>elif</code>, and <code>else</code> statements allow you to execute blocks of code based on Boolean conditions. <a href="https://docs.python.org/3/tutorial/controlflow.html#more-on-defining-functions">Learn more</a>.</p>
</li>
<li><p><strong>Loops</strong>: Python supports <code>for</code> and <code>while</code> loops, which enable you to iterate over sequences or repeat actions until a condition is met. For more details, refer to the <a href="https://docs.python.org/3/tutorial/controlflow.html">Python tutorial</a>.</p>
</li>
</ul>
<h2 id="4-functions-and-modules">4. Functions and Modules</h2>
<p>Functions are reusable blocks of code that perform specific tasks, while modules are files containing Python definitions and statements. Organizing your code into functions and modules enhances readability and reusability.</p>
<ul>
<li><p><strong>Defining Functions</strong>: Use the <code>def</code> keyword to create functions. Functions can take arguments and return values. Explore more about function definitions in the <a href="https://docs.python.org/3/tutorial/controlflow.html#more-on-defining-functions">Python documentation</a>.</p>
</li>
<li><p><strong>Using Modules</strong>: Modules allow you to organize your code by grouping related functions, classes, and variables. Learn how to import and use modules in the <a href="https://docs.python.org/3/tutorial/modules.html">official Python tutorial</a>.</p>
</li>
</ul>
<h2 id="5-interactive-mode-and-scripting">5. Interactive Mode and Scripting</h2>
<p>Python can be used interactively or to write scripts. </p>
<ul>
<li><p><strong>Interactive Mode</strong>: Useful for quick tests and explorations. Type <code>python</code> in your command line to enter the interactive mode. Read more about it <a href="https://docs.python.org/3/tutorial/appendix.html#interactive-mode">here</a>.</p>
</li>
<li><p><strong>Scripting</strong>: Write your code in <code>.py</code> files and execute them in the terminal. Scripting is ideal for larger, reusable programs.</p>
</li>
</ul>
<h2 id="6-python-resources-and-tutorials">6. Python Resources and Tutorials</h2>
<p>To further your understanding, explore these resources:</p>
<h3 id="suggested-tutorials-">Suggested Tutorials:</h3>
<ul>
<li><a href="https://neuroimaging-data-science.org/content/003-programming/001-python-language.html">Python Language Overview - Neuroimaging Data Science</a></li>
<li><a href="https://cs50.harvard.edu/python/2022/">Introduction to Python - CS50 Harvard</a></li>
</ul>
<h3 id="supplemental-materials-">Supplemental Materials:</h3>
<ul>
<li><a href="https://peps.python.org/pep-0008/">PEP 8 - Python's Style Guide</a></li>
<li><a href="https://docs.python.org/3/tutorial/modules.html">Python Modules Documentation</a></li>
<li><a href="https://docs.python.org/3/tutorial/controlflow.html">Control Flow - Python Docs</a></li>
</ul>
</div>
</div>
<!-- Place the bird image and text anywhere on the page -->
<div style="text-align: right; padding-right: 40px;">
<a href="python_libraries.html">
<img src="images/small_bird_arrow.png" alt="Next Page" style="width: 100px; height: 100px;">
<div style="font-size: 18px; margin-top: 10px;">Next Page</div>
</a>
</div>
<!-- Footer -->
<footer id="footer">
<div class="inner">
<section>
<h2>Funding</h2>
<p> We would like to express our heartfelt gratitude to <strong>Neurohackademy</strong> at the <strong>University of Washington eScience Institute</strong> for providing invaluable training and support. This experience has significantly enriched our understanding of neuroimaging and data science. We also acknowledge the support of the National Institute of Mental Health (NIMH) grant number <strong>5R25MH112480-08</strong>, which made this opportunity possible.</p>
</section>
<section>
<h2>Follow</h2>
<ul class="icons">
<li><a href="https://x.com/Neuro_Nest" class="icon brands style2 fa-twitter"><span class="label">Twitter</span></a></li>
<li><a href="https://github.com/NeuroHackademy2024/NeuroNest" class="icon brands style2 fa-github"><span class="label">GitHub</span></a></li>
<li><a href="mailto:sopkoc@umich.edu" class="icon solid style2 fa-envelope"><span class="label">Email</span></a></li>
</ul>
</section>
<ul class="copyright">
<li>© Untitled. All rights reserved</li><li>Design: <a href="http://html5up.net">HTML5 UP</a></li>
</ul>
</div>
</footer>
</div>
<!-- Scripts -->
<script src="assets/js/jquery.min.js"></script>
<script src="assets/js/browser.min.js"></script>
<script src="assets/js/breakpoints.min.js"></script>
<script src="assets/js/util.js"></script>
<script src="assets/js/main.js"></script>
</body>
</html>