python - 设置没有默认数据类型的变量
问题描述
我正在创建一个函数来解析带有硒的页面
def get_position_links(start_url, browser):
"""
Retrieve the position_links
"""
position_links = []
next_page_element = ""
next_page_attribute = ""
#kick off
browser.get(start_url)
def get_position_links_and_next_page_elememnt_in_the_current_page(position_links):
##Get the position_links within the page
#browser change appropriately with the page change
nonlocal next_page_element
nonlocal next_page_attribute
position_elements = browser.find_elements_by_class_name("position_link") # Retrieve the postions link elements
#select those only contain python in the title
position_elements = [p for p in position_elements if "python" in p.text.lower()]
#position_links as global variable set at the top
position_links.extend([p.get_attribute("href") for p in position_elements])
#nonlocal to avoied repeated return
next_page_element = browser.find_element_by_class_name("pager_next")
#next_page_attribute for the while flag.
next_page_attribute = next_page_element.get_attribute("class").strip()
#handle the start_url
get_position_links_and_next_page_elememnt_in_the_current_page()
#Traverse until there's no next pages.
while not next_page_attribute.endswith("disabled"):
# time.sleep(random.uniform(1,20))
next_page_element.click()
get_position_links_and_next_page_elememnt_in_the_current_page()
return position_links
在我声明的封闭函数中 next_page_element = ""
next_page_attribute = ""
,我不确定它们的数据类型。
但是,我应该为它们随机设置一个数据类型,
我怎么能设置一个没有默认数据类型的变量,比如
var nextPageElement
var nextPageAttribute
在 Javascript 中?
解决方案
您可以使用此函数来查找变量的数据类型。
类型()
例如,
a = 1.0
print(type(a))
Output: <class 'float'>
显式数据类型转换称为“类型转换”
显式数据类型转换的一般形式是
> (required_data_type)(expression)
您可以深入研究一些常用的显式数据类型转换。
链接:https ://www.datacamp.com/community/tutorials/python-data-type-conversion
推荐阅读
- node.js - 如何检测用户是否回复了 discord.js 中的机器人消息?
- javascript - 如何在 div 中居中“头像”材质 UI 组件?使用 ReactJS 和材质 UI
- usb - USB 与 OTG 硬件差异
- python - 如何使用 Python 将列中的值设置为另一列中的另一个值
- android - 如何将调试符号添加到 build.gradle android studio 4.2
- mysql - 有没有一种方法可以在 Azure 或 AWS 中存储图像,而无需在其平台上托管应用程序?
- swift - SwiftUI @State 值不会改变
- vue.js - 如何将 VueJS 3 Hello World 应用程序作为库提供?
- rust - key-> HashSet 的 BTreeMap 中的借用问题
- visual-studio-code - 如何在 VS Code 中更改终端的活动选项卡边框颜色