• python基础----环境搭建-----01


    一 python介绍

    1.1 Python 特点

    • Python 是完全面向对象的语言。
    • 函数、模块、数宁、宁符串都是对象,在 Python 中一切皆对象
    • 完全支持继承、重载、多重继承。
    • 支持重载运算符,也支持泛型设计。
    • Python 拥有一个强大的标准库,Python 语言的核心只包含 数字、字符串、列表、宁典、文件 等常见类型和函数,而由 Pvthon 标准库提供了 系统管理、网络通信、文本处理、数据库接口、图形系统XML 处理 等额外的功能。
    • Python 社区提供了大量的第三方模块,使用方式与标准库类似。它们的功能覆盖 科学计算、人工智能、机器学习、Web 开发、数据库接口、图形系统 多个领域。

    二 搭建环境

    2.1 下载python解释器

    首先下载安装包,网址为https://www.python.org/downloads/windows/。这里选择windows版本的3.10.11,注意win7无法使用这么新的版本,需要选择低一点版本的安装包。然后直接安装即可。
    安装可以参考:python安装教程(Windows最新)
    在这里插入图片描述
    安装成功。
    在这里插入图片描述

    2.2 下载安装pycharm

    pycharm是一个ide,方便我们编写python代码。
    下载地址:https://www.jetbrains.com/pycharm/download/#section=windows

    具体安装请参考:pycharm安装教程,超详细

    三 测试

    创建一个新项目。输入以下代码:

    # This is a sample Python script.
    
    # Press Shift+F10 to execute it or replace it with your code.
    # Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
    
    
    def print_hi(name):
        # Use a breakpoint in the code line below to debug your script.
        print(f'Hi, {name}')  # Press Ctrl+F8 to toggle the breakpoint.
    
    
    # Press the green button in the gutter to run the script.
    if __name__ == '__main__':
        print_hi('PyCharm')
    
    # See PyCharm help at https://www.jetbrains.com/help/pycharm/
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17

    运行看到结果:
    在这里插入图片描述

    或者输入点有趣的测试代码:

    # !/usr/bin/env python3
    # -*- coding: utf-8 -*-
    # @Author: dong
    # @Date: 2018-07-05 19:37:42
    # @Env: python 3.6
    # @Github: https://github.com/PerpetualSmile
    
    from turtle import *
    
    
    # 无轨迹跳跃
    def my_goto(x, y):
        penup()
        goto(x, y)
        pendown()
    
    # 眼睛
    def eyes():
        fillcolor("#ffffff")
        begin_fill()
    
        tracer(False)
        a = 2.5
        for i in range(120):
            if 0 <= i < 30 or 60 <= i < 90:
                a -= 0.05
                lt(3)
                fd(a)
            else:
                a += 0.05
                lt(3)
                fd(a)
        tracer(True)
        end_fill()
    
    
    # 胡须
    def beard():
        my_goto(-32, 135)
        seth(165)
        fd(60)
    
        my_goto(-32, 125)
        seth(180)
        fd(60)
    
        my_goto(-32, 115)
        seth(193)
        fd(60)
    
        my_goto(37, 135)
        seth(15)
        fd(60)
    
        my_goto(37, 125)
        seth(0)
        fd(60)
    
        my_goto(37, 115)
        seth(-13)
        fd(60)
    
    # 嘴巴
    def mouth():
        my_goto(5, 148)
        seth(270)
        fd(100)
        seth(0)
        circle(120, 50)
        seth(230)
        circle(-120, 100)
    
    # 围巾
    def scarf():
        fillcolor('#e70010')
        begin_fill()
        seth(0)
        fd(200)
        circle(-5, 90)
        fd(10)
        circle(-5, 90)
        fd(207)
        circle(-5, 90)
        fd(10)
        circle(-5, 90)
        end_fill()
    
    # 鼻子
    def nose():
        my_goto(-10, 158)
        seth(315)
        fillcolor('#e70010')
        begin_fill()
        circle(20)
        end_fill()
    
    # 黑眼睛
    def black_eyes():
        seth(0)
        my_goto(-20, 195)
        fillcolor('#000000')
        begin_fill()
        circle(13)
        end_fill()
    
        pensize(6)
        my_goto(20, 205)
        seth(75)
        circle(-10, 150)
        pensize(3)
    
        my_goto(-17, 200)
        seth(0)
        fillcolor('#ffffff')
        begin_fill()
        circle(5)
        end_fill()
        my_goto(0, 0)
    
    
    
    # 脸
    def face():
    
        fd(183)
        lt(45)
        fillcolor('#ffffff')
        begin_fill()
        circle(120, 100)
        seth(180)
        # print(pos())
        fd(121)
        pendown()
        seth(215)
        circle(120, 100)
        end_fill()
        my_goto(63.56,218.24)
        seth(90)
        eyes()
        seth(180)
        penup()
        fd(60)
        pendown()
        seth(90)
        eyes()
        penup()
        seth(180)
        fd(64)
    
    # 头型
    def head():
        penup()
        circle(150, 40)
        pendown()
        fillcolor('#00a0de')
        begin_fill()
        circle(150, 280)
        end_fill()
    
    # 画哆啦A梦
    def Doraemon():
        # 头部
        head()
    
        # 围脖
        scarf()
    
        # 脸
        face()
    
        # 红鼻子
        nose()
    
        # 嘴巴
        mouth()
    
        # 胡须
        beard()
    
        # 身体
        my_goto(0, 0)
        seth(0)
        penup()
        circle(150, 50)
        pendown()
        seth(30)
        fd(40)
        seth(70)
        circle(-30, 270)
    
    
        fillcolor('#00a0de')
        begin_fill()
    
        seth(230)
        fd(80)
        seth(90)
        circle(1000, 1)
        seth(-89)
        circle(-1000, 10)
    
        # print(pos())
    
        seth(180)
        fd(70)
        seth(90)
        circle(30, 180)
        seth(180)
        fd(70)
    
        # print(pos())
        seth(100)
        circle(-1000, 9)
    
        seth(-86)
        circle(1000, 2)
        seth(230)
        fd(40)
    
        # print(pos())
    
    
        circle(-30, 230)
        seth(45)
        fd(81)
        seth(0)
        fd(203)
        circle(5, 90)
        fd(10)
        circle(5, 90)
        fd(7)
        seth(40)
        circle(150, 10)
        seth(30)
        fd(40)
        end_fill()
    
        # 左手
        seth(70)
        fillcolor('#ffffff')
        begin_fill()
        circle(-30)
        end_fill()
    
        # 脚
        my_goto(103.74, -182.59)
        seth(0)
        fillcolor('#ffffff')
        begin_fill()
        fd(15)
        circle(-15, 180)
        fd(90)
        circle(-15, 180)
        fd(10)
        end_fill()
    
        my_goto(-96.26, -182.59)
        seth(180)
        fillcolor('#ffffff')
        begin_fill()
        fd(15)
        circle(15, 180)
        fd(90)
        circle(15, 180)
        fd(10)
        end_fill()
    
        # 右手
        my_goto(-133.97, -91.81)
        seth(50)
        fillcolor('#ffffff')
        begin_fill()
        circle(30)
        end_fill()
    
        # 口袋
        my_goto(-103.42, 15.09)
        seth(0)
        fd(38)
        seth(230)
        begin_fill()
        circle(90, 260)
        end_fill()
    
        my_goto(5, -40)
        seth(0)
        fd(70)
        seth(-90)
        circle(-70, 180)
        seth(0)
        fd(70)
    
        #铃铛
        my_goto(-103.42, 15.09)
        fd(90)
        seth(70)
        fillcolor('#ffd200')
        # print(pos())
        begin_fill()
        circle(-20)
        end_fill()
        seth(170)
        fillcolor('#ffd200')
        begin_fill()
        circle(-2, 180)
        seth(10)
        circle(-100, 22)
        circle(-2, 180)
        seth(180-10)
        circle(100, 22)
        end_fill()
        goto(-13.42, 15.09)
        seth(250)
        circle(20, 110)
        seth(90)
        fd(15)
        dot(10)
        my_goto(0, -150)
    
        # 画眼睛
        black_eyes()
    
    if __name__ == '__main__':
        screensize(800,600, "#f0f0f0")
        pensize(3)  # 画笔宽度
        speed(9)    # 画笔速度
        Doraemon()
        my_goto(100, -300)
        write('by dongdong', font=("Bradley Hand ITC", 30, "bold"))
        mainloop()
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174
    • 175
    • 176
    • 177
    • 178
    • 179
    • 180
    • 181
    • 182
    • 183
    • 184
    • 185
    • 186
    • 187
    • 188
    • 189
    • 190
    • 191
    • 192
    • 193
    • 194
    • 195
    • 196
    • 197
    • 198
    • 199
    • 200
    • 201
    • 202
    • 203
    • 204
    • 205
    • 206
    • 207
    • 208
    • 209
    • 210
    • 211
    • 212
    • 213
    • 214
    • 215
    • 216
    • 217
    • 218
    • 219
    • 220
    • 221
    • 222
    • 223
    • 224
    • 225
    • 226
    • 227
    • 228
    • 229
    • 230
    • 231
    • 232
    • 233
    • 234
    • 235
    • 236
    • 237
    • 238
    • 239
    • 240
    • 241
    • 242
    • 243
    • 244
    • 245
    • 246
    • 247
    • 248
    • 249
    • 250
    • 251
    • 252
    • 253
    • 254
    • 255
    • 256
    • 257
    • 258
    • 259
    • 260
    • 261
    • 262
    • 263
    • 264
    • 265
    • 266
    • 267
    • 268
    • 269
    • 270
    • 271
    • 272
    • 273
    • 274
    • 275
    • 276
    • 277
    • 278
    • 279
    • 280
    • 281
    • 282
    • 283
    • 284
    • 285
    • 286
    • 287
    • 288
    • 289
    • 290
    • 291
    • 292
    • 293
    • 294
    • 295
    • 296
    • 297
    • 298
    • 299
    • 300
    • 301
    • 302
    • 303
    • 304
    • 305
    • 306
    • 307
    • 308
    • 309
    • 310
    • 311
    • 312
    • 313
    • 314
    • 315
    • 316
    • 317
    • 318
    • 319
    • 320
    • 321
    • 322
    • 323
    • 324
    • 325
    • 326
    • 327
    • 328
    • 329
    • 330
    • 331

    在这里插入图片描述

  • 相关阅读:
    新系列:地狱挖掘者——贪食的炼狱来了!
    后端面试---分布式&&微服务
    建设现代智能工业-智能化、数字化、自动化节能减排
    一篇文章教会你利用红黑树实现map和set的封装
    一篇博客带你学会MyBatis
    Android 生成并分享海报,到微信
    tomcat启动报错Cannot find usrlocaltomcatbinsetclasspath.sh原因
    【python入门篇】元组、字典和集合(3)
    Datagrip:高效数据库管理和开发
    阿里云人脸识别对比
  • 原文地址:https://blog.csdn.net/weixin_44517656/article/details/130910518