1. What is YAML?
Ans:- YAML is a human-readable data serialization format commonly used for configuration files and data exchange between languages with different data structures.
2. Is YAML a programming language?
Ans:- No, YAML is not a programming language. It is a data serialization language designed to be easy to read and write by humans.
3. What does YAML stand for?
Ans:- YAML stands for “YAML Ain’t Markup Language” or sometimes recursively as “YAML Ain’t Markup Language.”
4. What are the main use cases for YAML?
Ans:- YAML is commonly used for configuration files, data exchange between languages, and representing data structures in a human-readable format.
5. How are data structures represented in YAML?
Ans:- YAML represents data structures using indentation and a simple syntax, including key-value pairs, lists, and nested structures.
6. What are the basic data types supported by YAML?
Ans:- YAML supports scalars (strings, numbers, and booleans), sequences (arrays/lists), and mappings (key-value pairs).
7. How is a comment written in YAML?
Ans:- YAML uses the # symbol to indicate comments. Everything following the # on a line is considered a comment.
8. Can YAML files have extensions?
Ans:- YAML files commonly have the extension .yaml or .yml, but it’s not mandatory.
9. What is the difference between JSON and YAML?
Ans:- JSON uses braces and commas, while YAML uses indentation and dashes or colons. YAML is often considered more human-readable.
10. Can YAML files include other YAML files?
Ans:- Yes, YAML supports the !include directive to include content from other YAML files.
11. How does YAML handle multi-line strings?
Ans:- Multi-line strings in YAML can be represented using the > or | characters, allowing for more readable text blocks.
12. What is a YAML document?
Ans:- A YAML document is a valid YAML data structure, which can include scalars, sequences, mappings, and other YAML elements.
13. How is a sequence (list) represented in YAML?
Ans:- A sequence in YAML is represented using a dash – for each item in the list.
14. How is a mapping (dictionary) represented in YAML?
Ans:- A mapping in YAML is represented using key-value pairs, with a colon : separating the key and value.
15. What is the difference between a block scalar and a flow scalar in YAML?
Ans:- A block scalar in YAML is written with indentation and line breaks, while a flow scalar is written on a single line.
16. Can YAML be used with languages other than Python?
Ans:- Yes, YAML is language-agnostic and can be used with a variety of programming languages, including JavaScript, Ruby, and others.
17. What is the significance of indentation in YAML?
Ans:- Indentation is crucial in YAML and signifies the structure of the data. It is used to define nesting and hierarchy.
18. Can YAML be used for complex data structures?
Ans:- Yes, YAML supports complex data structures, including nested sequences and mappings, making it suitable for various scenarios.
19. How does YAML handle null values?
Ans:- YAML represents null values using the null or ~ keyword.
20. What is an anchor in YAML?
Ans:- An anchor in YAML is a way to mark a node in the document, allowing it to be referenced elsewhere in the document.
21. How does YAML handle special characters in strings?
Ans:- YAML uses escape sequences, such as \n for newline and \t for tab, to represent special characters in strings.
22. Can YAML documents have multiple documents in a single file?
Ans:- Yes, YAML supports multiple documents in a single file by separating them with three consecutive dashes —.
23. How does YAML handle boolean values?
Ans:- YAML represents boolean values as true or false.
24. What is a tag in YAML?
Ans:- A tag in YAML is a way to give a node a specific type or meaning, helping applications interpret the data correctly.
25. Can YAML include inline comments?
Ans:- No, YAML does not support inline comments. Comments are written on separate lines preceded by the # symbol.
26. How does YAML handle dates and timestamps?
Ans:- YAML has a specific timestamp format, and it can represent dates using the !!timestamp tag.
27. What is the difference between a YAML stream and a YAML document?
Ans:- A YAML stream is a collection of documents, while a YAML document is a single valid YAML data structure.
28. How is a YAML alias used?
Ans:- An alias in YAML is created using the & symbol, and it can be referenced elsewhere using the * symbol followed by the alias name.
29. Can YAML include references to external resources?
Ans:- YAML does not have built-in support for referencing external resources, but applications parsing YAML may provide such functionality.
30. How does YAML handle line breaks in strings?
Ans:- YAML preserves line breaks in strings, and they are represented as \n when necessary.
31. What is the purpose of the YAML header?
Ans:- YAML files typically do not have headers. However, a header may refer to the start of a YAML document or the start of a stream.
32. Can YAML be used for configuration files in web development?
Ans:- Yes, YAML is commonly used for configuration files in web development due to its readability and ease of use.
33. How does YAML handle type casting?
Ans:- YAML does implicit type casting based on the context, but it also supports explicit type tags to specify the desired type.
34. What is the significance of the … (three dots) in YAML?
Ans:- The … (three dots) in YAML indicates the end of a document or a stream.
35. How does YAML handle integers and floating-point numbers?
Ans:- YAML represents integers and floating-point numbers without explicit type indicators.
36. Can YAML be used for serializing and deserializing complex data structures?
Ans:- Yes, YAML is commonly used for serializing and deserializing complex data structures in a readable and portable format.
37. How does YAML handle character encoding?
Ans:- YAML is typically UTF-8 encoded, but it can support other encodings as well.
38. What is the difference between single and double quotes in YAML strings?
Ans:- Single quotes in YAML preserve literal meaning, while double quotes allow for escape sequences and interpretation.
39. Can YAML include directives to control parsing behavior?
Ans:- YAML supports directives, such as %YAML and %TAG, to provide information about the version and tags used in the document.
40. How does YAML handle duplicate keys in a mapping?
Ans:- YAML does not allow duplicate keys in a mapping. If duplicates are encountered, it is considered an error.
41. Can YAML include anchors and references across different documents in a stream?
Ans:- No, YAML anchors and references are scoped within a single document and cannot be used across different documents in a stream.
42. How does YAML handle complex structures like graphs?
Ans:- YAML can represent complex structures like graphs using its support for nested mappings, sequences, and anchors.
43. What is the role of YAML schemas in data validation?
Ans:- YAML schemas define the expected structure of YAML documents and can be used for data validation.
44. Can YAML be used for storing localization data?
Ans:- Yes, YAML is suitable for storing localization data, thanks to its readability and support for nested structures.
45. How does YAML handle circular references in data structures?
Ans:- YAML cannot handle circular references directly, and attempting to represent them will result in an error.
46. What is the role of YAML linters?
Ans:- YAML linters analyze YAML files for syntax errors, style issues, and potential problems, helping maintain code quality.
47. How does YAML handle inline arrays and mappings?
Ans:- YAML allows inline representation of arrays and mappings using square brackets for arrays and curly braces for mappings.
48. What is the significance of the % character in YAML?
Ans:- The % character is used in YAML directives, such as %YAML and %TAG, to provide information about the document.
49. How does YAML handle empty strings and null values?
Ans:- YAML represents empty strings as “” and null values as null or ~.
50. Can YAML be used for inter-process communication?
Ans:- Yes, YAML can be used for inter-process communication by representing data structures in a standardized format that multiple processes can understand.