玩转 ”hello word“,Python程序员大多数都没有实现过

很多人学习Python很长时间,对于'hello word' 的认知,很多已经从事Python多年的程序员的认知也就只有:

print(hello wrod)

但是有没有让hello word 变得不一样?让你装一下逼?(想要源码可以加群:725479218,群文件里面可以找到)

开始 (先决条件)

首先在你的操作系统上安装 Anaconda (Python)。你可以从官方网站下载 anaconda 并自行安装,或者你可以按照以下这些 anaconda 安装教程进行安装。

  • 在 Windows 上安装 Anaconda:

  • 在 Mac 上安装 Anaconda:

  • 在 Ubuntu (Linux) 上安装 Anaconda:

(不会的,或者想获取安装方法的可以加群:725479218)

打开一个 Jupyter Notebook

打开你的终端(Mac)或命令行,并输入以下内容(请参考视频中的 1:16 处)来打开 Jupyter Notebook:

jupyter notebook

打印语句/Hello World

在 Jupyter 的单元格中输入以下内容并按下 shift + 回车来执行代码。

扫描二维码关注公众号,回复: 1438819 查看本文章
# This is a one line comment
print('Hello World!')

效果如下图

 

字符串和字符串操作

字符串是 Python 类的一种特殊类型。作为对象,在类中,你可以使用 .methodName() 来调用字符串对象的方法。字符串类在 Python 中默认是可用的,所以你不需要 import 语句来使用字符串对象接口。

# Create a variable
# Variables are used to store information to be referenced
# and manipulated in a computer program.
firstVariable = 'Hello World'
print(firstVariable)
 
输出打印变量 firstVariable
# Explore what various string methods
print(firstVariable.lower())
print(firstVariable.upper())
print(firstVariable.title())
 
使用 .lower()、.upper() 和 title() 方法输出
# Use the split method to convert your string into a list
print(firstVariable.split(' '))
 
使用 split 方法输出(此例中以空格分隔)
# You can add strings together.
a = "Fizz" + "Buzz"
print(a)
 
字符串连接

查询方法的功能

对于新程序员,他们经常问你如何知道每种方法的功能。Python 提供了两种方法来实现。
1、(在不在 Jupyter Notebook 中都可用)使用 help 查询每个方法的功能。

 
查询每个方法的功能

2.(Jupyter Notebook 专用)你也可以通过在方法之后添加问号来查找方法的功能。

# To look up what each method does in jupyter (doesnt work outside of jupyter)

firstVariable.lower?
 
在 Jupyter 中查找每个方法的功能

结束语

如果你对本文或在 YouTube 视频的评论部分有任何疑问,请告诉我们。
还有其他的教程,需要的可以加群:725479218,群内提供技术分享、技术交流,需要学习资料的可以找群主。

 很多人学习Python很长时间,对于'hello word' 的认知,很多已经从事Python多年的程序员的认知也就只有:```print(hello wrod)```但是有没有让hello word 变得不一样?让你装一下逼?(想要**源码**可以加群:725479218,群文件里面可以找到)
##### 开始 (先决条件)
首先在你的操作系统上安装 Anaconda (Python)。你可以从官方网站下载 anaconda 并自行安装,或者你可以按照以下这些 anaconda 安装教程进行安装。
* 在 Windows 上安装 Anaconda:
* 在 Mac 上安装 Anaconda:
*  在 Ubuntu (Linux) 上安装 Anaconda:
(不会的,或者想**获取安装方法**的可以加群:725479218)
#### 打开一个 Jupyter Notebook
打开你的终端(Mac)或命令行,并输入以下内容(请参考视频中的 1:16 处)来打开 Jupyter Notebook:
jupyter notebook
打印语句/Hello World
在 Jupyter 的单元格中输入以下内容并按下 shift + 回车来执行代码。```# This is a one line commentprint('Hello World!')```效果如下图![](https://upload-images.jianshu.io/upload_images/11678829-58bf95d3e32356d1.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

#### 字符串和字符串操作
字符串是 Python 类的一种特殊类型。作为对象,在类中,你可以使用 .methodName() 来调用字符串对象的方法。字符串类在 Python 中默认是可用的,所以你不需要 import 语句来使用字符串对象接口。
```# Create a variable# Variables are used to store information to be referenced# and manipulated in a computer program.firstVariable = 'Hello World'print(firstVariable)```
![输出打印变量 firstVariable](https://upload-images.jianshu.io/upload_images/11678829-f38304c8f8f8bab4.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)```# Explore what various string methodsprint(firstVariable.lower())print(firstVariable.upper())print(firstVariable.title())```![使用 .lower()、.upper() 和 title() 方法输出](https://upload-images.jianshu.io/upload_images/11678829-0abc495aeb7c43e6.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)```# Use the split method to convert your string into a listprint(firstVariable.split(' '))```![使用 split 方法输出(此例中以空格分隔)](https://upload-images.jianshu.io/upload_images/11678829-dd3fd9e364ebaffe.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)```# You can add strings together.a = "Fizz" + "Buzz"print(a)```
![字符串连接](https://upload-images.jianshu.io/upload_images/11678829-0ffa190ec3531ee4.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
#### 查询方法的功能
对于新程序员,他们经常问你如何知道每种方法的功能。Python 提供了两种方法来实现。1、(在不在 Jupyter Notebook 中都可用)使用 help 查询每个方法的功能。
![查询每个方法的功能](//upload-images.jianshu.io/upload_images/11678829-fdf596915762d324.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
2.(Jupyter Notebook 专用)你也可以通过在方法之后添加问号来查找方法的功能。```# To look up what each method does in jupyter (doesnt work outside of jupyter)
firstVariable.lower?```![在 Jupyter 中查找每个方法的功能](https://upload-images.jianshu.io/upload_images/11678829-3345bd5842a9e78a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
#### 结束语
如果你对本文或在 YouTube 视频的评论部分有任何疑问,请告诉我们。还有其他的教程,需要的可以加群:725479218,群内提供技术分享、技术交流,需要学习资料的可以找群主。

猜你喜欢

转载自www.cnblogs.com/CoXieLearnPython/p/9131350.html
今日推荐