目录

Concatenating Strings

Long Strings

Raw Strings

A Quick Summary

Algorithms:

Variables:

Statements:

Functions:

Modules:

Strings:

New Functions in This Chapter

What Now?


The hash sign (#) is a bit special in Python. When you put it in your code, everything to the right of it is ignored。

# Print the circumference of the circle:
print(2 * pi * radius)

The first line here is called a comment, which can be useful in making programs easier to understand—
both for other people and for yourself when you come back to old code.

If it was hard to write, it should be hard to read

Make sure your comments say significant things and don’t simply restate what is already obvious from the code. Useless, redundant comments may be worse than none. For example, in the following, a comment isn’t really called for:

# Get the user's name:
user_name = input("What is your name?")

Concatenating Strings

>>> "Let's say " '"Hello, world!"'
'Let\'s say "Hello, world!"'

I’ve simply written two strings, one after the other, and Python automatically concatenates them (makes
them into one string). This mechanism isn’t used very often, but it can be useful at times. However, it works
only when you actually write both strings at the same time, directly following one another.

>>> x = "Hello, "
>>> y = "world!"
>>> x y
SyntaxError: invalid syntax

In other words, this is just a special way of writing strings, not a general method of concatenating them.

Long Strings

If you want to write a really long string, one that spans several lines, you can use triple quotes instead of
ordinary quotes

print('''This is a very long string. It continues here.
And it's not over yet. "Hello, world!"
Still here.''')

You can also use triple double quotes, """like this""".

>>> 1 + 2 + \
4 + 5
12

Raw Strings

>>> print(r'C:\nowhere')
C:\nowhere
>>> print(r'C:\Program Files\fnord\foo\bar\baz\frozz\bozz')
C:\Program Files\fnord\foo\bar\baz\frozz\bozz

As you can see, raw strings are prefixed with an r.

A Quick Summary

Algorithms:

An algorithm is a recipe telling you exactly how to perform a task.When you program a computer, you are essentially describing an algorithm in a language the computer can understand, such as Python. Such a machinefriendly description is called a program, and it mainly consists of expressions and statements.

Algorithm is just a fancy word for a procedure or recipe—a detailed description of how to do something.

Variables:

A variable is a name that represents a value. New values may be assigned to variables through assignments such as x = 2. An assignment is a kind of statement.

Statements:

A statement is an instruction that tells the computer to do something. That may involve changing variables (through assignments), printing things to the screen (such as print("Hello, world!")), importing modules, or doing a host of other stuff.

Functions:

Functions in Python work just like functions in mathematics: they may take some arguments, and they return a result.

Modules:

Modules are extensions that can be imported into Python to extend its capabilities. For example, several useful mathematical functions are available in the math module.

Strings:

Strings are really simple—they are just pieces of text, with characters represented as Unicode code points. And yet there is a lot to know about them.

New Functions in This Chapter

What Now?

Now that you know the basics of expressions, let’s move on to something a bit more advanced: data
structures. Instead of dealing with simple values (such as numbers), you’ll see how to bunch them together
in more complex structures, such as lists and dictionaries.

Beginning Python chapter 1 Instant Hacking The Basics 2: Comments Strings相关推荐

  1. 转贴一篇不错的Python入门教程 - Instant Hacking[译文]

    为什么80%的码农都做不了架构师?>>>    原文 http://www.hetland.org/python/instant-hacking.php Instant Hackin ...

  2. Beginning Python PDF 分享

    链接:https://pan.baidu.com/s/11ojPYBn-_RZ5dPCHyvOJbA            eb6e 相关推荐 python基础教程 Python语言入门 Python ...

  3. Think Python - Chapter 12 Tuples

    12.1 Tuples are immutable(元组是不可变的) A tuple is a sequence of values. The values can be any type, and ...

  4. 一篇不错的Python入门教程

    原文  http://www.hetland.org/python/instant-hacking.php Instant Hacking[译文] 译者: 肯定来过 这是一篇简短的关于python程序 ...

  5. DataCamp中Introduction to Python之Python Basics练习

    DataCamp的Introduction to Python之Python Basics是一些比较基础的练习,可以很快掌握. The Python Interface In the Python s ...

  6. Python for Data Analysis v2 | Notes_ Chapter 3 Python 的数据结构、函数和文件

    本人以简书作者 SeanCheney 系列专题文章并结合原书为学习资源,记录个人笔记,仅作为知识记录及后期复习所用,原作者地址查看 简书 SeanCheney,如有错误,还望批评指教.--ZJ 原作者 ...

  7. Free Download Top 100 Hacking Books

    2019独角兽企业重金招聘Python工程师标准>>> Kali Linux – Assuring Security by Penetration Testing Network A ...

  8. Python算法(含源代码下载)

    关键字:Python Algorithms Python算法  Mastering Basic Algorithms in the Python Language 使用Python语言掌握基本算法 P ...

  9. python工程师_我作为石油工程师学习python的旅程

    python工程师 To be called literate in the 2020s there is a good chance you must know how to code. It ma ...

  10. python的1000+篇文章总结

    python的1000+篇文章总结 本文收集和总结了有关python的1000+篇文章,由于篇幅有限只能总结近期的内容,想了解更多内容可以访问:http://www.ai2news.com/, 其分享 ...

最新文章

  1. 38.什么是PV操作
  2. 重温WEB开发系列(二)HTML HEAD
  3. 让系统尽量不用swap
  4. 【数据结构与算法】之深入解析“不同路径III”的求解思路与算法示例
  5. 算法图解:如何用两个栈实现一个队列?
  6. 用C#完成Swift远程推送通知
  7. Swoole HTTP 的应用
  8. linux的python2.7的paramiko_centos7 python2.7下安装paramiko模块
  9. labview 快捷键
  10. cocostudio基础 教程
  11. nupkg 本地安装_关于Visual Studio:如何在本地安装NuGet包.nupkg文件?
  12. 计算机开机切换用户界面,win7开机登录界面怎么设置?win7更换开机画面壁纸解决办法...
  13. 常见的概率论问题清单及其答案
  14. 设备管理---要点练习及总结
  15. [2022软工第三次作业]结对编程项目——最长英语单词链
  16. unity之摇杆和NPC
  17. 成功解决python.exe 无法找到程序入口 无法定位程序输入点
  18. html给下拉菜单设置背景色,如何更改下拉菜单活动背景的颜色(即。tk.列表框)在一个ttk.组合框...
  19. ubuntu14.04 刚安装完成后汉语拼音输入法出错问题的解决办法
  20. 付费计算机毕业论文毕业设计课程设计

热门文章

  1. python的序列类型包括_python基础之常用序列类型(字符串)
  2. dw中创建java程序_新建MainGame.java并创建窗口
  3. 微信头像失效_如何判断微信授权的头像是否失效
  4. 流类库——输入输出流控制详解
  5. 加固社交关系 派派“场景+娱乐”模式异军突起
  6. docker 系列 - 基础镜像环境和Docker常用命令整理
  7. JavaScript—常见设计模式整理(27)
  8. [Linux实用工具]Windows下同步Linux文件(Linux安装Samba和配置)
  9. oracle获取表或视图的字段名、数据类型、注释
  10. 菜鸟学习linux笔记(二)