Python编程从入门到实践-学习笔记之一

interpreter n.解释程序

compile vt.编译

utility n.实用;实用程序

terminal n.终端

sublime a.崇高的;v.升华

apostrophe n.撇号

第1章 起步

搭建编程环境

C:\Users\zhouzb>python --version
Python 3.10.8

文本编辑器Geany-1.38

设置生成命令

C:\python\python310\python -m py_compile "%f"

C:\python\python310\python "%f"

从终端运行Python程序

新建工作目录:C:\python\python_work

cd c:\python\python_work

hello_world.py

print("Hello Python world!")

message = "Hello Python world!-2"
print(message)

message = "Hello Python Crash Course world!"
print(message)

C:\python\python310\python hello_word.py

PS:

终端命令

cd 切换目录(change directory)

dir 显示当前目录中所有未隐藏文件(directory)

cls 清屏(clear screen)

第2章 变量和简单数据类型

字符串、合并(拼接)字符串、使用制表符或换行符来添加空白、删除空白

name.py

name = "ada lovelace"

print(name.title())
# Ada Lovelace

print(name.upper())
# ADA LOVELACE

print(name.lower())
# ada lovelace

first_name = "ada"
last_name = "lovelace"
full_name = first_name + " " + last_name
print(full_name)

print("Hello, " + full_name.title() + "!")

message = "Hello, " + full_name.title() + "!"
print(message)

print("\tPython")

print("Languages:\nPython\nC\nJavaScript")

print("Languages:\n\tPython\n\tC\n\tJavaScript")

favorite_language = " python "
print(favorite_language)
print(favorite_language.rstrip())
print(favorite_language.lstrip())
print(favorite_language.strip())
print(favorite_language)
favorite_language = favorite_language.strip()
print(favorite_language)

# name.title(),name后面的.让Python对变量name执行方法title()指定的操作。每个方法后面都跟着一对(),这是因为方法通常需要额外的信息来完成其工作,这种信息是在()内提供的。

# 对变量favorite_language调用方法rstrip()后,多余的空格被删除了,然而,这种删除只是暂时的,接下来再次访问favorite_language的值时,依然包含多余的空白。要永久删除这个字符串中的空白,必须将删除操作的结果存回到变量中。

apostrophe.py

message = "One of Python's strengths is its diverse community."
print(message)

数字

使用函数str()避免类型错误

birthday.py

age = 23
message = "Happy " + str(age) + "rd Birthday!"
print(message)

注释

comment.py

# 向大家问好
print("Hello Python people!")

使用Geany运行提示错误:

SyntaxError: Non-UTF-8 code starting with '\xcf' in file C:\Python\python_work\comment.py on line 2, but no encoding declared; see https://python.org/dev/peps/pep-0263/ for details

注释中不能使用中文!!!

# say hello
print("Hello Python people!")

Python之禅

C:\Users\zhouzb>python
Python 3.10.8 (tags/v3.10.8:aaaf517, Oct 11 2022, 16:50:30) [MSC v.1933 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import this
The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
>>>

2023年9月7日

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

逆旅匆匆

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值