Not logged in
Talk
Contributions
Create account
Log in
Navigation
Main page
About
People
Publications
Teaching
Resources
Research Blog
Wiki Functions
Recent changes
Help
Licensing
Page
Discussion
Edit
View history
Editing
Intro to Programming and Data Science (Fall 2024)/Day 1 Tutorial
(section)
From CommunityData
Jump to:
navigation
,
search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Variables== [[File:Fraction.png|100px]] A lot of work gets done in Python using variables. Variables are a lot like the variables in math class, except that in Python variables can be of any data type, not just numbers. <syntaxhighlight lang="python"> type(4)</syntaxhighlight> <syntaxhighlight lang="python"> x = 4 </syntaxhighlight> <syntaxhighlight lang="python"> x </syntaxhighlight> <syntaxhighlight lang="python"> type(x) </syntaxhighlight> <syntaxhighlight lang="python"> 2 * x </syntaxhighlight> Giving a name to something, so that you can refer to it by that name, is called '''assignment'''. Above, we assigned the name 'x' to 4, and after that we can use <code>x</code> wherever we want to use the number 4. You'll see that there wasn't any output here when you ''assigned'' 4 to <code>x</code>; that's fine! Not all Python operations have output, and in fact most of the time that's what you expect. Variables can't have spaces or other special characters, and they need to start with a letter. Here are some valid variable names: <syntaxhighlight lang="python"> magic_number = 1500 amountOfFlour = .75 my_name = "Jessica" </syntaxhighlight> Projects develop naming conventions: maybe multi-word variable names use underscores (like <code>magic_number</code>), or "camel case" (like <code>amountOfFlour</code>). The most important thing is to be consistent within a project, because it makes the code more readable.
Summary:
Please note that all contributions to CommunityData are considered to be released under the Attribution-Share Alike 3.0 Unported (see
CommunityData:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
To protect the wiki against automated edit spam, we kindly ask you to solve the following CAPTCHA:
Cancel
Editing help
(opens in new window)
Tools
What links here
Related changes
Special pages
Page information