-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
61 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
user1 = {'name': 'tom', 'hp': 100} | ||
user2 = {'name': 'jerry', 'hp': 80} | ||
|
||
|
||
def print_role(rolename): | ||
print('name is %s, hp is %s' % (rolename['name'], rolename['hp'])) | ||
|
||
|
||
print_role(user1) | ||
|
||
|
||
class Player(): # 定义一个函数 | ||
def __init__(self, name, hp, occ): | ||
self.__name = name # 下划线开头的属性只能通过方法访问和修改 | ||
self.hp = hp | ||
self.occ = occ | ||
|
||
def print_role(self): | ||
print('%s: %s %s' % (self.__name, self.hp, self.occ)) | ||
|
||
def update_name(self,new_name): | ||
self.__name = new_name | ||
|
||
|
||
class Monster(): | ||
'定义怪物类' | ||
pass | ||
|
||
|
||
user1 = Player('tom', 100, 'war') # 类实例化 | ||
user2 = Player('jerry', 90, 'master') | ||
user1.print_role() | ||
user2.print_role() | ||
|
||
user1.update_name('wilson') | ||
user1.print_role() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import mymod | ||
|
||
mymod.print_me() | ||
|
||
|
||
# | ||
# brew install autopep8 或者 pip install autopep8 | ||
# 打开PyCharm | ||
# | ||
# File → Settings → Tools → External Tools → + | ||
# | ||
# 配置参数 | ||
# | ||
# Name: autopep8 | ||
# Program: autopep8 | ||
# Arguments: --in-place --aggressive --aggressive $FilePath$ | ||
# Working directory: $ProjectFileDir$ | ||
# Output filters: $FILE_PATH$\:$LINE$\:$COLUMN$\:.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
def print_me(): | ||
print('me') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,4 +20,5 @@ | |
def func(filename): | ||
print(open(filename).read()) | ||
|
||
|
||
func('name.txt') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters