Skip to content

Latest commit

 

History

History
44 lines (23 loc) · 1.49 KB

a_PATH_method.md

File metadata and controls

44 lines (23 loc) · 1.49 KB

🟡 The Join() method


  • The join() method used with strings,

  • In contrast, the os.path.join() method is used for constructing file paths by joining different path components. a_PATH_JOIN


🧶 The join() & os.path.join()

  • The join() method used with strings (e.g., ", ".join(iterable)) is designed to concatenate a sequence of strings into a single string, inserting a specified delimiter between each element.

    • For example , ", ".join(["apple", "banana", "cherry"])
    • results in "apple, banana, cherry".

In contrast, the os.path.join() method is used for constructing file paths by joining different path components. It ensures that the appropriate file system separators are used for the operating system. For example, os.path.join("folder", "subfolder", "file.txt") produces a correctly formatted path such as "folder/subfolder/file.txt" on Unix-based systems or "folder\subfolder\file.txt" on Windows. This method simplifies path handling and enhances cross-platform compatibility.



🟠 Join the word

  • .join will turn the list into a string, separated by whatever the string is.

  • you can add white spaces, symbols, letters , example:

  • ' '.join or ', '.join or '/ '.join etc...

print("You have used these letters: ", ' '.join(used_letters))
# 🔴 output
"a", "b",
#
#https://github.com/nadiamariduena/python-intro-2024-privat/blob/master/LESSON_19_PPROJECTS/random_Hangman/README.md