ผลต่างระหว่างรุ่นของ "204111:Python missing details"

จาก Theory Wiki
ไปยังการนำทาง ไปยังการค้นหา
แถว 5: แถว 5:
 
When you want to use a variable, you have to give it a name.  This is also true, again, with functions that you want to create.  Providing good names helps people, including yourself, understand your programs faster and better.
 
When you want to use a variable, you have to give it a name.  This is also true, again, with functions that you want to create.  Providing good names helps people, including yourself, understand your programs faster and better.
  
In Python, there are rules regarding how to name things.  You can choose names like "<tt>x</tt>", "<tt>total</tt>", or even "<tt>I_love_You_so_Much</tt>", but you can't have variables or functions with names like "<tt>2things</tt>", "<tt>x/y</tt>", or "<tt>sum of numbers</tt>".
+
In Python, there are rules regarding how to name things.  You can choose names like "<tt>x</tt>", "<tt>total</tt>", or even "<tt>I_love_You_so_Much</tt>", but you can't have variables or functions with names like "<tt>2things</tt>", "<tt>x/y</tt>", or "<tt>sum of numbers</tt>". From this example, you can probably guess the reason.  These forbidden names confuse the Python interpreter.  For example, it would not be able to distinguish between a variable called <tt>x/y</tt> and an expression <tt>x/y</tt>
 +
 
 +
Here are the rules:
 +
 
 +
*
  
 
== String formatting ==
 
== String formatting ==
  
 
== Full operator precedence list ==
 
== Full operator precedence list ==

รุ่นแก้ไขเมื่อ 03:01, 7 กรกฎาคม 2553

There are a number of topics left out from the teaching slides, because they are not central in programming concepts. However, these are details that are useful. Many of these are related to Python syntax. Some is related to string formatting.

Naming rules

When you want to use a variable, you have to give it a name. This is also true, again, with functions that you want to create. Providing good names helps people, including yourself, understand your programs faster and better.

In Python, there are rules regarding how to name things. You can choose names like "x", "total", or even "I_love_You_so_Much", but you can't have variables or functions with names like "2things", "x/y", or "sum of numbers". From this example, you can probably guess the reason. These forbidden names confuse the Python interpreter. For example, it would not be able to distinguish between a variable called x/y and an expression x/y

Here are the rules:

String formatting

Full operator precedence list